ASP.NET is all about controls, so well be discussing them in greater detail as we
move through this book. In particular, Chapter 4 explains many of the controls
that ship with ASP.NET. For now, though, lets continue with our dissection of
an ASP.NET page.
Server-side Comments
Server-side comments allow you to include within the page comments or notes
that will not be processed by ASP.NET. Traditional HTML uses the <!-- and -
-> character sequences to delimit comments; any information included between
these tags will not be displayed to the user. ASP.NET comments look very similar,
but use the sequences <%-- and --%>.
Our ASP.NET example contains the following server-side comment block:
File: Hello.aspx (excerpt)
<%-- Declare the title as string and set it --%>
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
theyre 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 if 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, while we wont 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:
41
Server-side Comments

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.