Pardon my ASP ignorance, but what’s the difference?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
These are somewhat informally referred to as “bee stings”. There are 4 types:
<%# %> is invoked during the DataBinding phase.
<%= %> is used to get values from code to the UI layer. Meant for backward compatibility with ASP applications. Shouldn’t use in .NET.
<%@ %> represents directives and allow behaviors to be set without resorting to code.
<%: %> (introduced in ASP.NET 4) is the same as %=, but with the added functionality of HtmlEncoding the output. The intention is for this to be the default usage (over %=) to help shield against script injection attacks.
Directives specify settings that are
used by the page and user-control
compilers when the compilers process
ASP.NET Web Forms pages (.aspx files)
and user control (.ascx) files.ASP.NET treats any directive block
(<%@ %>) that does not contain an
explicit directive name as an @ Page
directive (for a page) or as an @
Control directive (for a user
control).
@Esteban – Added a msdn link to directives. If you need…more explanation, please let me know.
Method 2
As Albert says, it’s all to do with parsing databinding statements.
Method 3
The # version is used while data binding. <%= is just a simple Response.Write
Method 4
Not entirely related to the question, there’s another related notation in asp.net called Expression Builder:
<asp:SqlDataSource ... Runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>" /> <asp:Literal Runat="server" Text="<%$ Resources:MyResources, MyText %>" />
and it’s extensible, see http://msdn.microsoft.com/en-us/magazine/cc163849.aspx#S4
Method 5
javascript in .aspx that uses a master page.
var e = document.getElementById('<%= lblDescription.ClientID %>');
e.innerHTML = 'getElementById('lblDescription') will be null';
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0