开发者

Duplicate repeaters, identical UpdatePanels

Perhaps I'm making a faulty assumption here, but this has me stumped. I've got to set up two identical repeaters in two different places in the same control. I want to avoid changing the names of controls so I can use the same functions on the front end (and 开发者_开发百科actually, if there's a better way to have two identical repeaters in two different places other than a straight copy and paste, that'd be great). But for simplicity's sake, I've broken down the two as follows:

 <asp:Repeater ID="rptTest" runat="server">
    <ItemTemplate>
        <asp:UpdatePanel runat="server" ID="updTestPanel">
            <ContentTemplate>
                <asp:TextBox ID="txtTest" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:TextBox ID="txtTest2" runat="server" />
    </ItemTemplate>
</asp:Repeater>

<asp:Repeater ID="rptTest2" runat="server">
    <ItemTemplate>
        <asp:UpdatePanel runat="server" ID="updTestPanel">
            <ContentTemplate>
                <asp:TextBox ID="txtTest" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:TextBox ID="txtTest2" runat="server" />                            
    </ItemTemplate>
</asp:Repeater>

Here's the thing: txtTest2 is fine being repeated in both repeaters, but txtTest throws the following errors:

Error 4 'txtTest' is already declared as 'Protected WithEvents txtTest As System.Web.UI.WebControls.TextBox' in this class.

Error 5 'Private Overloads Function __BuildControltxtTest() As System.Web.UI.WebControls.TextBox' has multiple definitions with identical signatures.

Error 8 'txtTest' is already declared as 'Protected WithEvents txtTest As System.Web.UI.WebControls.TextBox' in this class.

Is there a way to do what I'm trying to do, or do I need to rethink how I'm calling in asynchronous data in the repeater?


Without knowing too much as to what you are trying to do, the approach you have will work - but you cannot have two controls with the same name on the page. They are all in 'page' scope, and hence will complain.

What I would suggest is to have the methods be different for each textbox inside the repeater, but have them call different methods. In those methods, you can just pass the texbox values to a centralized method which will actually do the work. This way, you don't have to repeat the code, all you are doing is making two different functions that are the pass-thrus to your centralized method..


If you have controls that are DataBound (Repeater, DataList, FormVeiw, etc.) and under the updatepanel, these controls will have page level scope. You have to give them unique IDs, as I don't think that there is another work around for this problem. If you notice these controls are available on the page, without using FindControl.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜