skip to Main Content

So I’m working on this (horribly messy) website that I’m cleaning up the back and front end of. I’m not trying to delete any of the old code, however when I comment the old code out using <!-- -->, the code within it still gets compiled. This causes an error since I’m using the old label names in the new asp:Labels that I create.
There is no issue of syntax or there being a bug in the new code that causes this glitch, when I delete the old commented out code – everything compiles as normal. The glitch only occurs if the commented out code uses the same labels. The existence of the labels being used twice is what causes the issue here (which is strange because the second instance is in a comment).
Example:

<div class="col-16">
   <asp:Label ID="myLabel" runat="server" Text="example text"></asp:Label>
</div>

<!-- OLD CODE
<td class="auto-style6">
   <b>
      <asp:Label ID="myLabel" runat="server" Text="example text"></asp:Label>
   </b>
</td>
-->

I’m using Visual Studio 2019 with ASP.net. The only thing that fixes this is by quite literally deleting the old code. We don’t use git (long story) so falling back on version control isn’t the best option here.
It is worth noting my editor is a bit strange, where it doesn’t let me comment out code automatically by using cntrl + /. I have to manually type out <!-- -->

2

Answers


  1. Since the control is set to runat="server" try using a server side comment.

    One common question people ask is what the difference is between using client-side HTML comments and server-side comments. The key difference is that with client-side comments it is the browser which is ignoring the content within them. Code/controls within client-side comments will still be executed on the server and sent down to the browser. As such, if there is a server error caused within them it will block running the page.

    https://weblogs.asp.net/scottgu/Tip_2F00_Trick_3A00_-Using-Server-Side-Comments-with-ASP.NET-2.0-

    Login or Signup to reply.
  2. Interesting!

    What version of .net framework are you using?

    When working in Visual studio, be it markup, code, css, and in fact EVEN when working in SQL server studio?

    You can highlight the text in question, and then go ctrl-k, ctrl-c (to comment the code). And then ctrl-k, ctrl-u to un-comment.

    so, say this markup:

    enter image description here

    So, using above (highlight text), and then ctrl k, ctrl-c, we see that a "<%–" is being used here, and not your "<!–".

    And if you do this from the VS menu, you get the same results.

    e.g., this:

    enter image description here

    So, using the menu from VS, or the shortcut of ctrl-k, ctrl-c ?

    This should work. You’re using the HTML comment out, but as you found out, it does not work with server-side markup. However, the above use of the "server side" tag in that markup to comment out that area should work fine for your needs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search