Server Side Comments in ASP.NET

Date: 16 Jan 2010 Comments: 3 so far

Sometimes when I develop my website there’s some code in the

aspx pages that I want to comment for test purpose. Other situation is when I find some bug, ex. adding comments doesn’t work, I’d comment the ‘Add New Comment Control’ while I’m fixing the bug and then it will be uncomment again.

In ASP.NET 2.0 or later it can be done by adding <%– –%>, ex:

<%–
<asp:TextBox ID=”_someTextBox” runat=”server”></asp:TextBox>

–%>

The content between <%– and –%> will be ignored by the asp.net compiler and nothing of it will be sent to the user’s browser when visit current page. That’s the difference between Server Side Comments and Client Side Comments (), ex.

If you add the following code in your aspx page:

<!–
<asp:TextBox ID=”_someTextBox” runat=”server”></asp:TextBox>
–>

Then run the aspx page in your browser, the asp.net code will be rendered as something like that:

<!–
<input name=”ctl00$_mainContentPlaceHolder$_someTextBox” type=”text” id=”ctl00__mainContentPlaceHolder__someTextBox” />
–>

In conclusion, if you want to comment something in your asp.net project and want it not to be rendered by the compiler and/or not to be sent to the client, you’d better use the server side commenting with <%– –%>.

Do you use Server Side Comments in ASP.NET?
  1. 3 Comments to “Server Side Comments in ASP.NET”

    1. Makra says:

      It’s for commenting not .

    2. Makra says:

      Sorry the blog removed the code in my post.

    3. asp.net comments using server side comments that can disabled code controls in the page. Because AJAX enabled the comment form.

    Leave a Reply