开发者

FormView templates break when refactored to Master/Content

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?


I'm giving up on this tactic as this question: FormView on a Master Page can't see databound controls through ContentPlaceHolder boundary seems to destroy any hope of this working the way I want it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜