How to comment out an ASP.NET server control – doesn’t work – level 100

I was performing some testing, so I commented out a bit of my ASP.NET markup with <!– –> because, after all, I’ve used that for years, right?  Well, it took me just a sec to figure out that the server control was still being executed and that the <!– was just rendered before it on the client.  The important bit:  <!– is HTML syntax, not server-side syntax.  If you want to comment out a server control, use the following syntax:

<%–   <asp:Button . . . . />  –%>

7 comments

  1. saurabh

    this is really cool . i too saw this behavior..

    Saurabh

  2. Michael Polo

    I think it will only comment out one control at a time….

  3. Jason Hoekstra

    Great tip … works for me. 🙂

  4. Ken Jackson

    I actually googled for this Jeff and got your page. Isn’t that cool! Thanks for the tip…

  5. Steve Branson

    Perfect solution to an annoying problem. Thanks! (found with google)

  6. Paul

    using <%— —%> is for many lines, How would you comment out just one line of code?

  7. Timothy

    Thanks so much.
    Very helpful

Comments are closed.