.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

Use server-side comments to temporary disable part of ASP.NET page

You are coding away on an ASP.NET page, and are trying to isolate a problem within the page. You have some existing html/controls/markup/in-line code that is being used on the page, and you want to temporarily comment it out while you fix the problem.
ASP.NET supports a little known feature called “server-side comments” that you can use to completely disable code/controls/html in a page. Server-side comments in ASP.NET are delimited using a <%-- --%> syntax. For example:

    <%--

        Commented out HTML/CODE/Markup. Anything with

        this block will not be parsed/handled by ASP.NET.

 

        <asp:Calendar runat="server"></asp:Calendar>

        <%# Eval("SomeProperty") %>

    --%>

The key difference between client-side HTML comments and server-side comments is that with client-side comments code/controls will still be executed on the server. With server-side comments, the ASP.NET compiler will ignore everything whithin these blocks.

7/21/2007
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.