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?
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
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.
Method 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 %>
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