Meaning of the various symbols in .aspx page of asp.net
Asked Answered
S

2

31

I have come across different symbols in .aspx page of asp.net

<%#eval(expr) %> 
<%#bind(expr) %>
<% %>  - for specifying the c# code in aspx page
<%$ %> - for specifying the SQL connection string in <asp:SqlDataSource>

Is there any underlying logic behind these symbols or is it just syntax which we have to remember blindly? What does <% %> mean in general?

Supply answered 29/4, 2011 at 14:18 Comment(0)
B
45

It is just syntax.

<% %> is simply short for <script runat="server"> </script> aka code render blocks.

<%# %> are binding expressions (plus the above).

<%= %> is the above + a Response.Write().

<%: %> is the above + a Response.Write() wrapped in Html.Encode (new in .NET 4.0).

<%$ %> is an ASP.NET expression, used to bind configuration or resource file data during runtime.

Beaver answered 29/4, 2011 at 14:20 Comment(6)
Thanks for your response, could you cite any references on this information? I have tried to find this in documentation many times, with no results. Also, what about <%$ %> ?Santoyo
@Santoyo - Follow the links. I don't know about <%$ %>.Beaver
I did some digging based of your initial links and I found out that <%$ %> is called an ASP.NET Expression and allows you to pull values from configuration or resource files.Santoyo
<% ... %> is not simply short for <script runat=server>! Such blocks (<% ... %>) contain code that becomes a part of the Render() method, while <script runat=server> blocks contain methods and other class members themselves.Bojorquez
Another construct is <%-- .. --%> for comment blocks (that won't turn up in the resulting HTML).Domesticate
I realise this is nearly 5 years later, but might be worth adding to your list the <%#: %> notation... which is the HTML encoded version of the binding expression that was added as part of ASP.NET 4.5Gothic
U
2

Remember it. It's more poorly documented ASP.net syntax to help maintain inconsistencies and fallout from ASP 'classic' groans. Also don't forget

<%=variablename %>  
Unsheathe answered 29/4, 2011 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.