0

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?

zed
  • 2,298
  • 4
  • 27
  • 44
Ryan
  • 17,511
  • 23
  • 63
  • 88

5 Answers5

1

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);       
}
zed
  • 2,298
  • 4
  • 27
  • 44
Russ Cam
  • 124,184
  • 33
  • 204
  • 266
0

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

Dan Diplo
  • 25,076
  • 4
  • 67
  • 89
  • The problem is that the method (click event of the button) where I would call update() is causing the full page to post back. It needs to be a trigger to let the page know just to update that panel. – Ryan Jul 27 '09 at 20:01
  • Ahh, got you. You'll probably need to add an asp:AsyncPostBackTrigger referencing the button in the update panel triggers. – Dan Diplo Jul 27 '09 at 20:16
0

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();
JBrooks
  • 9,901
  • 2
  • 28
  • 32
0

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

Like This ?

Radu094
  • 28,068
  • 16
  • 63
  • 80
  • The link does not exist anymore. Please edit this answer to add relevant contents from external link, otherwise this answer won't make sense. – zed Feb 18 '18 at 15:06
0

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.

Middletone
  • 4,190
  • 12
  • 53
  • 74