Information on <%# ... %> in .NET - asp.net

Can someone point me in the right direction of some information on using:
<%# ... %>
It seems Google does not like <%# as a search term. I don't even know what such a construct is called.
Or maybe someone can give me a brief description of how it works?

It is a data-binding expression. Look here for a start.

This is used to reference DataItems in a DataBound control. Here's the MSDN ASP.NET data binding overview.

It's data binding syntax
http://www.15seconds.com/Issue/040630.htm

It can also be used to get around the error "The Controls collection cannot be modified because the control contains code blocks" as seen here link

Related

Import HTML page in .NET

The following code imports an HTML page (which simply holds one table) into my .ASP page. This works great, but I now am converting into .NET and am having obstacles.
<% Response.Write(getFilesContent("table.htm")) %>
This code does not work in .NET, and I read that this method is not recommended or widely used? Are there any thoughts, advice, or solutions about this?
I simply want to import this HTML page to read in a content box within my .NET page. In essence, the .NET page is hosting the HTML table.
Any help would be greatly appreciated.
Thank you in advance for your time and help.
To get you started, take a look at the System.Net.WebClient class http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.80%29.aspx
In particular, the "DownloadXXX" methods.
You could put the table in an asp.net user control
A asp.net custom user control can act like an include that encapsulates asp.net
markup.
here is a tutorial:
http://ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index1.html
After you create the control add a reference
<%#Register tagprefix="uc" Tagname="html" src="custom_html.ascx" %>
then just a the control markup (in this case <uc:html runat="server"/>)
It would be cool the create a control the reads an html file by adding a src property
Try this:
<% Response.Write(New StreamReader(Server.MapPath("~/table.htm")).ReadToEnd()) %>

What functions are allowed inside <%# ... %> tags?

In ASP.NET, what functions are allowed inside the <%# %> tags? I frequently use Databinder.Eval(), and I know some basic things like CStr(), but where can I find a complete list with documentation? I would look myself, but honestly I don't even know what the name of the <%# %> tags are.
It's funny that nobody really knows what these are called - I think in the ASP.NET MVC team they call them Code Nuggets. Others call them Code Rendering Blocks.
Anyway, this is essential reading: http://quickstarts.asp.net/QuickstartV20/aspnet/doc/pages/syntax.aspx
Here is some specific info on the <%# Data Binding Syntax: http://msdn.microsoft.com/en-us/library/bda9bbfx%28v=VS.100%29.aspx
And this helped me understand the Eval voodoo: http://weblogs.asp.net/rajbk/archive/2004/07/20/what-s-the-deal-with-databinder-eval-and-container-dataitem.aspx
Anything that is in scope. E.g. public/protected methods on your page, public methods in some referenced namespace/class, etc. In addition to things that are related to the current NamingContainer you're within.

what is the meaning of this?

I know that this will sound stupid to some of you, but when an ASPX page has something like this:
<%# Page Title="[$TITLES_listevents{uneditable}]" Language="C#" MasterPageFile="~/sitebase/templates/page.master" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="list" %>`
or something like:
<div id="panelGroupEventPackageOnlyDescription" runat="server" visible="<%# ShowGroupEventPackageOnly %>">
[$ITEMLIST_groupeventpackageonly]
</div>
what does it mean?
Regards
I'm assuming that your query is for the bits that look like this: Title="[$TITLES_listevents{uneditable}]"
It doesn't look like asp.net to me. It could be that the page was generated by a templating tool that left some rubbish behind, is it in source control, can you ask whoever created the page?
Hey All,
apparently it means that It will use site text to set the title, this is done when there is an xml file that produces site data and you need some of those data to be published dynamically to you front end website. this is the results of custom controls being used on things like label, dropdownbox etc...
this is one of the legacy piece of software where the one who wrote the code is gone AWOL with little doc, only happens when you are emerging from recession lol.....

In ASP.NET what is the name for HTML directive symbols <%# or <%= etc for executing code on the server side?

Was trying to reference this the other day, and I've heard them called several things.
They are intrinsically hard to google for. Does this syntax have a proper name? Thanks!
The Visual Web Developer Team calls them "Code Nuggets," but I don't think there's an official term that'll help you find them in MSDN.
You might be interested in the following MSDN articles:
Code Render Blocks
Data-Binding Expression Syntax
Web Forms Syntax Reference
I call all variations of <% %> server tags. Dont know if they have another name.
I've always known them as "Expressions" (and/or "Code Expressions", "ASP.NET Expressions", and a few other variations).
I've heard that they are called constructs.
I think they don't have a collective name. The links to MSDN in this article all call them with different names - Embedded Code Blocks (pure <% %>), construct (<%= %>), Data-binding syntax (<%# %>), ASP.NET Expressions (<%$ %>, Directives (<%# ... %>), Server-side comments ( <%-- ... --%> ). The article itself calls them inline ASP.NET tags.
AFAIK, there is no common name for these constructions, but we use inline asp.net tags (* found a while ago here).
MSDN refers to them as Embedded Code Blocks.

Using ASP.NET MVC with generic views

I am currently investigating MVC for a new project we are starting. So far I like it, but I'm wondering about something.
The actual views that we will be displaying will not be known at design time, we will be specifying in a config file somewhere how to build these views. Is this pattern supported by MVC or do we need to know at design time exactly what data we will be viewing?
If not, can someone give me some pointers on what I should be looking at as most of the info I have assumes that you have a model/view that is defined during your design.
Regards,
Alex..
You can have your views weakly-typed... Your initial page directive on the view will look like:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
... and then you can refer to data from your Controllers like this:
<%= ViewData["MyData"] %>
Is there some common interface that you are intending to pass to your view? If so, you can benefit from a using the generic ViewPage<> :
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IamTheInterface>" %>
Then, you can use your interface to refer to your Model:
<%= Model.MyProperty %>
There is cool post in LosTechies.com about building an "autoform" with fields autogenerated from the Model properties. Take a look, it might be what you are looking for.

Resources