Question

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?

Was it helpful?

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);       
}

OTHER TIPS

Maybe I am missing some subtlety here, but can't you just call the Update() method on the Update Panel?

You can use the following pattern to control a panel postback in JavaScript:

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm._panelsToRefreshIDs = UPComments.uniqueID;
prm._doPostBack(eventTarget,eventArgument);
theForm.submit();

Can't you just add an AsyncPostBackTrigger programmatically from the code-behind?

Like This ?

just put the contents of the Panel in an update panel sothat you have:

Your user control here.

this will also prevent the popup from disapearing until you want it to.

In your code behind you can then call it with popup.show(0 or pop.hide() and link these to your user control by addin gan event ot it and handling it inyour pages code behind. this way your user control can direct the popup what to do and when. you can even for it to update hte update panel if you needed for some reason.


for the case above tha tI just realized is tha tyou wan to updat ehte panel in the control. Create a method i nthe control that calls the update method o teh update panel an dthen fire that event from your page. It's the same principal in reverse. By utilizing event well you can wire up your application to do some pretty cool stuff.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top