27

What is the correct way to comment inside an .aspx file?

The HTML syntax for a comment:

<!-- [COMMENT] -->

This doesn't work, I get the following: "ASP.NET runtime error:Only Content controls are allowed directly in a content page that contains Content controls."

I have also tried ', //, #, and --

Jim Dagg
  • 2,044
  • 22
  • 29
Jaiesh_bhai
  • 1,778
  • 8
  • 26
  • 41
  • possible duplicate of [Is there a way to comment out markup in an .ASPX page?](http://stackoverflow.com/questions/121382/is-there-a-way-to-comment-out-markup-in-an-aspx-page) – McGarnagle Sep 16 '13 at 19:48
  • there is something else wrong with your aspx file. You're probably using Masterpages and do not have the correct asp:content contentplaceholderid – Venkata Krishna Sep 16 '13 at 19:51
  • 1
    @McGarnagle - the one you have pointed is to comment out so it won't render in browser.. – Venkata Krishna Sep 16 '13 at 19:55

1 Answers1

43

Direct entry:

  • <%-- your comment --%>

Visual Studio:

  • comment & un-comment buttons on the toolbar
  • CTRL+KC (comment)
  • CTRL+KU (un-comment)
Chains
  • 12,541
  • 8
  • 45
  • 62
  • This worked. I had tried `<% %>` I didn't try `<%-- --%>` Thanks. – Jaiesh_bhai Sep 16 '13 at 20:18
  • 1
    Just a note: such comments won't render in the resulting HTML, so they're usually the preferred method (to keep the size down and to avoid people peeking at comments that are for your team's eyes only). If the classic HTML comment that was mentioned in the question is used instead, it will render in the resulting HTML and thus appear when someone does View (Page) Source in the browser (sometimes useful when debugging the resulting output). – George Birbilis Oct 26 '17 at 07:43