Thursday, 2 February 2012

Server-side Comments | ASP.Net Tutorial | ASP.Net Tutorial PDF

   Server-side comments allow you to include within the page comments or notes that won’t be processed by ASP.NET. Traditional HTML uses the <!--and -->character sequences to delimit comments; any information included between these tags won’t be displayed to the user. ASP.NET comments look very similar, but use the sequences <%--and --%>.
    Our ASP.NET example contains two server-side comment blocks, the first of which is the following:

                                 LearningASP\VB\Hello.aspx (excerpt)
<%-- Display the current date and time --%>
The difference between ASP.NET comments and HTML comments is that ASP.NET comments are not sent to the client at all; HTML comments are, so they’re not suited to commenting out ASP.NET code. Consider the following example:

C#
<!-<%
string Title = "This is generated by a code render block."; %>
<%= Title %>
-->
       Here, it looks as though a developer has attempted to use an HTML comment to stop a code render block from being executed. Unfortunately, HTML comments will only hide information from the browser, not the ASP.NET runtime. So in this case, although we won’t see anything in the browser that represents these two lines, they will be processed by ASP.NET, and the value of the variable Title will be sent to the browser inside an HTML comment, as shown here:
<!-This
code generated by a code render block.
-->
The code could be modified to use server-side comments very simply:
C#
<%--
<% string Title = "This is generated by a code render block."; %>
<%= Title %>
--%>
    The ASP.NET runtime will ignore the contents of this comment, and the value of the Title variable will not be output.