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

前端 未结 4 1962
轮回少年
轮回少年 2021-01-24 21:21

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

And that GridView contains a FileUpload control in footer and EmptyDataTemplate

相关标签:
4条回答
  • 2021-01-24 21:49

    Try registering the post back control from code behind like this:

    protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e)
        {
            LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd");
            if (btnAdd != null)
            {
                ScriptManager1.RegisterAsyncPostBackControl(btnAdd);
            }
        }
    
    0 讨论(0)
  • 2021-01-24 22:08

    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);
            }
    
        }
    
    0 讨论(0)
  • 2021-01-24 22:09

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

    I found another approach that always works which is to add triggers to the updatepanel 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 讨论(0)
  • 2021-01-24 22:12

    Instead of adding a trigger to upnlEditExpense maybe you can try to add an update panel around the link button inside the template with no 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>
    
    0 讨论(0)
提交回复
热议问题