Partager via


Server-Side Comments 

Server-side comments allow developers to embed code comments in any part of an ASP.NET application file (except for within <script> code blocks). Any content between opening and closing tags of server-side comment elements, whether ASP.NET code or literal text, will not be processed on the server or rendered to the resulting page.

<%-- Content of comments, or commented out server controls --%>

Remarks

ASP.NET server-side comment blocks have the same uses as traditional language-specific comment blocks, including documentation and testing. For example, you can use server-side comments to describe sections of markup in a file, or to comment out one or more server controls declared in a page. These comments can be used in most types of ASP.NET application files, including Web pages, user controls, Global.asax files, master pages, and skin files

Note that server-side comments are to be used in the body of the page, but not within blocks of server-side code. When you are using a specific language within code declaration blocks (code that is contained within the <script runat="server"></script> tags) or code render blocks (code that is contained within <% %> tags), you should use the comment syntax for the language that you are coding in.

A compilation error will occur if you use server-side comment blocks within <% %> blocks.

The opening and closing comment tags can appear on the same line of code or can be separated by many commented-out lines.

Server-side comment blocks cannot be nested.

Example

The following code example demonstrates a Button control that is commented out using server-side comments.

<%-- 
<asp:button runat="server" id="MyButton" 
  OnClick="MyButton_Click" />
--%>  

See Also

Other Resources

ASP.NET Page Syntax