asp.netwebformsupdatepanelpostbackpartial-postback

How can I update an UpdatePanel in a control from the page?


I have a modal on a page that also contains a user control.

When clicking the 'OK' button in the modal, I would like to update an UpdatePanel that is contained within the user control on the page.

Currently the 'OK' button on the modal does a full page postback, I'd like to just update the panel, but I'm not sure how to add it as a trigger since it's not in the control the UpdatePanel is.

Thanks.


I have a partial answer... I can update the panel once by doing this:

Dim addTrigger As New AsyncPostBackTrigger
addTrigger.ControlID = MyButton.ID
addTrigger.EventName = "Click"
MyUserControl.GetUpdatePanel.Triggers.Add(addTrigger)

This will cause a partial post-back the first time, but after that first time it causes an entire page reload. Any ideas?


Solution

  • You can explicitly add the OK button as a AsyncPostBackTrigger for the UpdatePanel.

    In the aspx markup for the UpdatePanel:

    <asp:UpdatePanel ID="updPanel" runat="server">
        <ContentTemplate>
        ....
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="the control" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    

    or in the code-behind:

    protected override void OnInit(EventArgs e)
    {
        AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
        trigger.ControlID = "the Control";
        trigger.EventName = "Click";
    
        updPanel.Triggers.Add(trigger);
    
        base.OnInit(e);       
    }