How to assign UpdatePanel trigger control identifier using a button from gridview

I currently have an UpdatePanel application for using jQuery Dialog that contains a GridView.

And that the GridView contains the FileUpload control in the footer and the EmptyDataTemplate

To make FileUpload file management work in javascript, I know that we need a trigger.

However, the button that I want to designate as a trigger is inside the GridView template ...

when the btnAdd button is pressed, the file in the 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 the trigger control id like this, an error occurs saying btnAdd cannot be found ...

What should I do to make FileUpload control work?

+1
source share
4 answers

It 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); } } 
+3
source

Try registering the control post-back from the code as follows:

 protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e) { LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd"); if (btnAdd != null) { ScriptManager1.RegisterAsyncPostBackControl(btnAdd); } } 
+2
source

Instead of adding a trigger for upnlEditExpense, perhaps you can try adding a refresh panel around the link button inside the template without triggers ...

 <asp:TemplateField> <FooterTemplate> <asp:UpdatePanel ID="upnlBtnAdd" runat="server"> <ContentTemplate> <asp:LinkButton runat="server" ID="btnAdd" Text="Add" OnClick="btnAdd_Click"></asp:LinkButton> </ContentTemplate> </asp:UpdatePanel> </FooterTemplate> </asp:TemplateField> 
+2
source

I had a similar problem and this post helped me, but I found that registering a control in the scriptmanager only works if UpdateMap UpdateMode is set to Always. If its set to "Conditional", this approach does not work.

I found another approach that always works to add triggers to the update panel in the DataBound () event of the gridview:

  Dim CheckBoxTrigger As UpdatePanelControlTrigger = New AsyncPostBackTrigger() Dim SelectCheckBox As CheckBox For i = 0 To GridViewEquipment.Rows.Count - 1 Step 1 SelectCheckBox = GridViewEquipment.Rows(i).Cells(12).FindControl("CheckBoxSign") CheckBoxTrigger.ControlID = SelectCheckBox.UniqueID UpdatePanelEquipment.Triggers.Add(CheckBoxTrigger) Next 
0
source

All Articles