0

why does my asp.net comment:

<!--<asp:HyperLink   
            ID="RandomFacts"   
            runat="server"  
            Text="Random Facts"  
            NavigateUrl="./RandomFacts.aspx">  
            </asp:HyperLink><br />-->

turn into:

<!--<a id="RandomFacts" href="./RandomFacts.aspx">Random Facts</a><br />-->

When I run the code and view the source in my web browser?

user2261573
  • 451
  • 2
  • 5
  • 8
  • That is a client-side comment, its content will still be seen by ASP.NET. See [Asp.net server-side code block explanations](http://stackoverflow.com/questions/6365017/asp-net-server-side-code-block-explanations). If you don't want the control to be rendered to HTML, comment it with server-side comments: `<%-- --%>`. – CodeCaster Jun 30 '13 at 08:27
  • 1
    Comment it within `<%--` and `--%>` – PSL Jun 30 '13 at 08:27

2 Answers2

1

You have used HTML comment. You need to replace it with a server side comment (<%-- --%>) if you don't want to get any execution of the block on the server:

<%--<asp:HyperLink   
        ID="RandomFacts"   
        runat="server"  
        Text="Random Facts"  
        NavigateUrl="./RandomFacts.aspx">  
        </asp:HyperLink><br />--%>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • OK, but even if it wasn't commented. Why does it get turned into a different piece of code? – user2261573 Jun 30 '13 at 13:09
  • @user2261573 because asp.net parses the code and transforms it into the link thats asp.net's job. a web browser would not understand unparsed asp.net – Nicholas King Jul 03 '13 at 15:31
0

An asp control such as <asp:Hyperlink... is only understood by IIS and not the browser. IIS converts each control to the HTML equivalent and therefore <asp:Hyperlink... changes to <a...

It does this even though you have commented it out because your comment is a client side comment which will only be processed by the browser.

Wize
  • 1,040
  • 9
  • 20