R – How to register click event of button in GridView header with ajax UpdatePanel

asp.netasp.net-ajaxgridviewupdatepanel

I have an UpdatePanel containing a GridView which contains a button in the HeaderTemplate of a TemplateField. I want to add this button's click event to the UpdatePanel's trigger collection but this doesn't seem to work as I get an error message saying that a control with the specified ID could not be found.

I thought of programmatically adding to the UpdatePanel's trigger collection on page load but this doesn't seem to be possible.

Is there a work-around to this problem? I'd ideally like to keep my button within the header of the GridView.

Best Answer

I've solved this by accessing the ScriptManager on the page instead of the UpdatePanel itself. I did this inside the Page_Load method. My code is as follows:

if (!Page.IsPostBack)
{
    Button button = GridView1.HeaderRow.FindControl("myHeaderButton") as Button;
    if (button != null)
        scriptManager.RegisterAsyncPostBackControl(button);
}
Related Topic