Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <%: %> and <%#: %> in Asp.Net

I know that we can <%: %> syntax for html encoding that is introduced in .Net 4. But I was reading new features of Asp.Net 4.5, and I got that we have another type i-e <%#: %> that is used for encoding the result of databind expression. I am confuse with this.

What is the difference between <%: %> and <%#: %> in Asp.Net

Please explain both of them.

like image 584
Idrees Khan Avatar asked Aug 27 '12 14:08

Idrees Khan


People also ask

Which inline ASP NET tag will HTML encode its contents?

Summary. The new <%: %> syntax provides a concise way to automatically HTML encode content and then render it as output.


2 Answers

The same way that <%: %> is the HTML encoded version of <%= %>, the <%#: %> tag is the HTML encoded version of <%# %>.

The <%#: %> tag does the same as <%# %>, but then it calls Server.HTMLEncode on the string.

like image 124
Guffa Avatar answered Oct 13 '22 01:10

Guffa


ASP.NET provides what's called a "binding" syntax to link HTML markup and controls to values extracted from data sources or other variables; that binding syntax is seen as something like:

<%# someVariable %>

The following colon merely extends the new "auto-HtmlEncode" behavior to the results of those bnding expressions.

Hope that helps.

like image 36
David W Avatar answered Oct 13 '22 01:10

David W