where we use <%@ %>
<%= %>
<%# %>
etc.
what else asp tags can be added in asp.net web pages?
Embedded code blocks are supported in ASP.NET Web pages primarily to preserve backward compatibility with older ASP technology. In general, using embedded code blocks for complex programming logic is not a best practice, because when the code is mixed on the page with markup, it can be difficult to debug and maintain.
In C#, a code block is a group of lines of code between curly braces {} . { //Everything between { and } is part of this code block. } Both selection statement keywords and loops work with code blocks, though in different ways.
The runat="server" tag in ASP.NET allows the ability to convert/treat most any HTML element as a server-side control that you can manipulate via code at generation time. Some controls have explicit implementations, others simply revert to a generic control implementation.
A directive controls how an ASP.NET page is compiled. The beginning of a directive is marked with the characters <%@ and the end of a directive is marked with the characters %>. A directive can appear anywhere within a page. By convention, however, a directive typically appears at the top of an ASP.NET page.
<%%>
is short hand for:
<script runat="server">
</script>
Anyting inside the <%
and %>
is server side code.
The other variants are also shortcuts:
<%@%>
is a page directrive<%=%>
is short for Response.Write
<%:%>
is short for Response.Write
, adding html encoding (introduced with .NET 4.0)<%#%>
is a binding expressionThis page is a good reference to all these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With