Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of the various symbols in .aspx page of asp.net

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?

like image 386
Sree Avatar asked Apr 29 '11 14:04

Sree


People also ask

What is the use of this symbol in asp net?

NET uses. This is used to indicate the beginning of a code-block, which basically allows you to use actual server-side code within your markup.

What does <% mean in ASPX?

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

What is ASPX in asp net?

Active Server Pages (ASPX) is a file format used by web servers and generated using the Microsoft ASP.NET framework - an open-source development framework used by web developers to create dynamic web pages, often with the . NET and C# programming languages.


2 Answers

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.

like image 91
Oded Avatar answered Sep 22 '22 21:09

Oded


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 %>   
like image 26
Doug Chamberlain Avatar answered Sep 25 '22 21:09

Doug Chamberlain