LoadControl and HTML Comments

Tags: .NET, SharePoint

Developin webparts with many UI elements can be a hassle - which is why I'm fond of the UserControl shortcut - I build my web UI as a WebUserControl, then simply have my webpart call Page.LoadControl to dynamically load that usercontrol.

A problem I've encountered with it today is that LoadControl, strangly enough, ignores HTML comment in the ASCX file.

Let's say I have the following code in the ASCX:

<!-- <asp:Repeater runat="server" id="Repeater1" /> -->
<asp:Repeater runat="server" id="Repeater1" />

This should instantiate only one Repeater object - and does, when the ASCX is hosted normally inside an ASPX page.
When I load it dynamically, though, I get an exception in LoadControl stating that "Parse Error: A control named Repeater1 is already defined" - meaning that for some reason it parses the first control too, even though it's commented out.
If I erase the commented section, it runs as planned.

Anyone know why it ignores my markup?

 

2 Comments

  • Gunnlaugur Thor Briem said

    No idea why that is. But I just checked back to correct myself: the two dashes in the ASP.NET comment end token *are* needed. The VS.NET syntax highlighter just doesn't know that, apparently :)

    My apologies for stating without testing! (a.k.a. talking out of my hind side)

Comments have been disabled for this content.