views:

382

answers:

6

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. I have done this before but am having a brain-fart at the moment. Currently the 'OK' button on the modal does a full page post, 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 update panel is. Thanks.

A: 

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?

Ryan
Is this code wrapped around en If Not Page.IsPostback... sounds that you're adding the trigger only on the initial page load... afterwards you loose it 'cuz this code is not beeing executed on postbacks...
Jaime
No, that was my initial thought too but its not inside of a !Postback condition, but certainly is acting like it is.
Ryan
Try running the above code after each partial postback. I believe the problem is with the UserControl... Since it's inside the UpdatePanel the ViewState tree is re-rendered and the trigger loses reference to it.
DennyDotNet
A: 

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

Dan Diplo
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
Ahh, got you. You'll probably need to add an asp:AsyncPostBackTrigger referencing the button in the update panel triggers.
Dan Diplo
A: 

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
A: 

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

Like This ?

Radu094
+1  A: 

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

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 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);       
    }
Russ Cam
A: 

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