Hi again,

I was wondering, how can I comment an asp tag, in HTML is <!-- -->, on ASP VB Code is ', but an ASP.NET tag like <asp:TextBox1 ></asp:Textbox1> how can I comment it?? I've tried with both HTML and ASP, but no luck. Is there a way to comment those?

Thanks!

Omar

Dani AI

Generated

Short answer: is on the right track — ASP.NET has a parser-level comment that prevents the control from being parsed or emitted, and that’s different from ordinary HTML comments. A few practical points and alternatives to consider so you pick the right approach.

HTML comments (the browser-style ones) do not reliably stop the ASP.NET parser from seeing server controls. If a control still exists in the control tree you can get designer or runtime complaints, and the control still participates in viewstate and events. If you want the markup completely ignored by ASP.NET (so it’s not compiled into the page at all), use the server-side/commenting approach that prevents parsing — this removes the control from the tree entirely.

If your goal is simply to hide the control at runtime but keep it accessible in code-behind, set the control’s Visible flag from code. For example, in C#:

TextBox1.Visible = false;

That keeps the control declared, preserves viewstate, and can be toggled on postback.

Another option is to avoid static markup and render the control conditionally from server code or wrap it in a server-side conditional block so it never gets emitted:

<% if (false) { %>
  <asp:TextBox ID="TextBox1" runat="server" />
<% } %>

Troubleshooting notes: if you remove or comment a server control but still reference it in code-behind or the designer file, you’ll get build errors — update or remove those declarations. Also remember Visual Studio’s “comment selection” for markup usually inserts HTML comments, not parser-level comments, so it may not do what you expect for server controls.

The asp.net comment mark is <%-- and --%>

It would have the same runtime effect as

Setting the Visible Property to False
or
In the page load event

textbox1.visible = False
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.