Search code examples
asp.netcommentsrepeater

Why can't I comment out an updatepanel in asp.net?


I made a blank page and added the following resulting in a correctly running page:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    </asp:UpdatePanel>

then i changed it to the following:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server">-->
    <!--</asp:UpdatePanel>-->

why is it this this results in an error saying i cant have a "-->" literal inside an update panel!?

thanks!


Solution

  • This is wrong:

    <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server">-->
    <!--</asp:UpdatePanel>-->
    

    This is correct:

    <%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        </asp:UpdatePanel>--%>
    

    EDIT:

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

    ASP.NET supports a little known feature called “server-side comments” that you can use to completely disable code/controls/html in a page. Server-side comments in ASP.NET are delimited using a <%-- --%>
    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.