FormView templates break when refactored to Master/Content
- by ZaijiaN
Let's say I have an abstract class IA, with subclasses A1, A2, A3.
For each subclass, I had a page with a FormView to insert/edit/view, with code specific to that class. The templates for insert/edit/view are all very similar, so it was mostly cut & paste, and the compiler had no problem that there were controls with the same IDs in the different templates.
Something like this:
<asp:FormView>
<InsertItemTemplate>
<asp:Label id="Label1" />
</InsertItemTemplate>
<EditItemTemplate>
<asp:Label id="Label1" />
</EdittItemTemplate>
</asp:FormView>
Much of the code/markup ended up being redundant across the pages, so I refactored it to use a master/content format, with the master page having content placeholders for the insert/edit/view templates.
Master page:
<asp:FormView>
<InsertItemTemplate>
<asp:ContentPlaceHolder ID="InsertItemTemplate"></asp:ContentPlaceHolder>
</InsertItemTemplate>
<EditItemTemplate>
<asp:ContentPlaceHolder ID="EditItemTemplate"></asp:ContentPlaceHolder>
</EdittItemTemplate>
</asp:FormView>
And content page:
<asp:Content ContentPlaceHolderID="InsertItemTemplate">
<asp:Label id="Label1" />
</asp:Content>
<asp:Content ContentPlaceHolderID="EditItemTemplate">
<asp:Label id="Label1" />
</asp:Content>
In the content page templates, I'm doing the exact same thing I was doing before I refactored, but now the compiler is blowing up with the error BC30260: 'Label1' is already declared as 'Protected WithEvents Label1 As System.Web.UI.WebControls.Label' in this class.
For some reason, it's not separating the controls in the content blocks the same way it did when they were in the templates, even though the content placeholders are in the individual templates.
Is there a way around this, other than to rename all my controls?