How to trigger UpdatePanel from a GridView Templat

2019-07-14 19:33发布

问题:

I have the following case, all my controls on an update panel on the page.

One of these controls is a GridView, this GridView contains a CheckBox on the header template field (to make a check all). The autopostback is true but when the check changed no thing is changed, the update panel has a trigger asynchronous post back for the GridView.

回答1:

You'll have to define an ASyncPostBackTrigger like so:

<asp:UpdatePanel>
 <Triggers>
         <asp:AsyncPostBackTrigger ControlID="yourCheckBox" />
  </Triggers>
<ContentTemplate>
...GridView etc
</ContentTemplate>
</asp:UpdatePanel>


回答2:

I just fixed this bug after searching everywhere and tried the last solution here with no success. So I first created an OnClick event in the CheckBox. In the Onclick function in the .cs file, make a call to the SelectedIndexChanged(new object(), new EventArgs()); method with arguments as given then just after call the Update method to your UpdatePanel.