How to assign UpdatePanel Trigger’s control ID with button’s from gridview

asp.netgridviewtriggersupdatepanel

currently I have a UpdatePanel for jQuery Dialog use, which contains a GridView.

And that GridView contains a FileUpload control in footer and EmptyDataTemplate

In order to get FileUpload control work in javascript, I know that we need trigger.

However, the button that I wanna assign as trigger is inside GridView's template…

when the button btnAdd clicked, file in FileUpload control will be saved.


Here is the code:

<asp:UpdatePanel ID="upnlEditExpense" runat="server">
      <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnAdd"/>
      </Triggers>
            ......................
                 ........................
                       .........................
      <asp:GridView runat="server" ID="grdExpense" ShowHeader="True" ShowFooter="True"
           AutoGenerateColumns="False">
           <Columns>
                 ...................
                 <asp:TemplateField>
                       <FooterTemplate>
                              <asp:LinkButton runat="server" ID="btnAdd" Text="Add" OnClick="btnAdd_Click"></asp:LinkButton>
                       </FooterTemplate>
                 </asp:TemplateField>
           </Columns>
      </asp:GridView>
</asp:UpdatePanel>

If I put the button id directly in trigger's control ID like this, error come up saying btnAdd could not be found…

what should I do to get FileUpload control work?

Best Answer

This works

protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e)
    {
        LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd");
        if (btnAdd != null)
        {
            ScriptManager.GetCurrent(this).RegisterPostBackControl(btnAdd);
        }

    }
Related Topic