Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Embedded Code Blocks in ASP.NET Web Pages?

Tags:

asp.net

where we use <%@ %> <%= %> <%# %> etc. what else asp tags can be added in asp.net web pages?

like image 614
ppp Avatar asked Sep 28 '10 11:09

ppp


People also ask

Is code that is embedded directly within the ASP.NET page?

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.

Can code blocks be used for C#?

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.

What does Runat server mean?

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.

What is ASP.NET page structure?

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.


1 Answers

<%%> 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 expression

This page is a good reference to all these.

like image 148
Oded Avatar answered Oct 27 '22 04:10

Oded