locked
How Update Panel works with repeater LinkButton RRS feed

  • Question

  • User-789100765 posted
    <div>
            <asp:UpdatePanel ID="updatePanelbooksGridView" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="booksGridView" OnPageIndexChanging="booksGridView_PageIndexChanging" runat="server" AllowPaging="True" PageSize="3" 
                        CellPadding="4" ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="booksLinkButton" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
        <div>
            <asp:UpdatePanel ID="updatePanelRepeater" runat="server">
                <ContentTemplate>
                    <asp:Repeater ID="booksRepeater" runat="server">
                        <ItemTemplate>
                            <asp:LinkButton ID="booksLinkButton" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%#Eval("Value") %>'
                                Enabled='<%#Eval("Enabled") %>' OnClick="booksLinkButton_Click"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:Repeater>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    
    I got error 
    A control with ID 'booksLinkButton' could not be found for the trigger in UpdatePanel 'updatePanelbooksGridView'. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidOperationException: A control with ID 'booksLinkButton' could not be found for the trigger in UpdatePanel 'updatePanelbooksGridView'.
    
    Source Error: 
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
    
    Can anyone help me how updatepanel works with repeater.
    Thanks in advanced...
    Wednesday, January 1, 2014 8:31 PM

Answers

  • User-789100765 posted

    Thanks to A2H Star... here is the solution.

        <div>
            <asp:UpdatePanel ID="updatePanelbooksGridView" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="booksGridView" OnPageIndexChanging="booksGridView_PageIndexChanging" runat="server" AllowPaging="True" PageSize="3" 
                        CellPadding="4" ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                <asp:AsyncPostBackTrigger ControlID="booksRepeater" EventName="ItemCreated" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
        <div>
            <asp:Repeater ID="booksRepeater" runat="server" 
                onitemcreated="booksRepeater_ItemCreated">
                <ItemTemplate>
                    <asp:UpdatePanel ID="updatePanelInsideRepeater" runat="server">
                        <ContentTemplate>
                            <asp:LinkButton ID="booksLinkButton" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%#Eval("Value") %>'
                                Enabled='<%#Eval("Enabled") %>'></asp:LinkButton>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ItemTemplate>
            </asp:Repeater>
                
        </div>
    

    here is code behind .cs

    protected void booksRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            ScriptManager scriptMan = ScriptManager.GetCurrent(this);
            LinkButton btn = e.Item.FindControl("booksLinkButton") as LinkButton;
            if (btn != null)
            {
                btn.Click += booksLinkButton_Click;
                scriptMan.RegisterAsyncPostBackControl(btn);
            }
    
        }
    
      protected void booksLinkButton_Click(object sender, EventArgs e)
        {
            //Do your stuff here
        }

    protected void booksGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //Bind your GridView datasource here();
            //booksGridView.DataBind();
        }
    
    
    

    it works perfect...

    Thanks...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 1, 2014 10:34 PM

All replies

  • User2103319870 posted

    how updatepanel works with repeater.

    Hi,

    Please try the solution suggeseted in below link

    Wednesday, January 1, 2014 9:12 PM
  • User-789100765 posted

    Thanks to A2H Star... here is the solution.

        <div>
            <asp:UpdatePanel ID="updatePanelbooksGridView" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="booksGridView" OnPageIndexChanging="booksGridView_PageIndexChanging" runat="server" AllowPaging="True" PageSize="3" 
                        CellPadding="4" ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                <asp:AsyncPostBackTrigger ControlID="booksRepeater" EventName="ItemCreated" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
        <div>
            <asp:Repeater ID="booksRepeater" runat="server" 
                onitemcreated="booksRepeater_ItemCreated">
                <ItemTemplate>
                    <asp:UpdatePanel ID="updatePanelInsideRepeater" runat="server">
                        <ContentTemplate>
                            <asp:LinkButton ID="booksLinkButton" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%#Eval("Value") %>'
                                Enabled='<%#Eval("Enabled") %>'></asp:LinkButton>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ItemTemplate>
            </asp:Repeater>
                
        </div>
    

    here is code behind .cs

    protected void booksRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            ScriptManager scriptMan = ScriptManager.GetCurrent(this);
            LinkButton btn = e.Item.FindControl("booksLinkButton") as LinkButton;
            if (btn != null)
            {
                btn.Click += booksLinkButton_Click;
                scriptMan.RegisterAsyncPostBackControl(btn);
            }
    
        }
    
      protected void booksLinkButton_Click(object sender, EventArgs e)
        {
            //Do your stuff here
        }

    protected void booksGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //Bind your GridView datasource here();
            //booksGridView.DataBind();
        }
    
    
    

    it works perfect...

    Thanks...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 1, 2014 10:34 PM