Ayende @ Rahien

It's a girl

Why isn't there a simple way to trigger an UpdatePanel from client script?

All I want is something in the order of:

$get('<%= MyUpdatePanel.ClientId %>').update();

You would think that this is elementry, but apperantly we get things like this, which involve tricking the UpdatePanel into triggering.



Justin-Josef Angel [MVP]
02/22/2007 07:44 PM by
Justin-Josef Angel [MVP]

Then you should probably use the UpdatePanel.Update client-side Method :)


Ayende Rahien
02/22/2007 09:43 PM by
Ayende Rahien


You pointed me at the SERVER reference, I need it from CLIENT.

What I am looking for is something like this:

<form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server" />


Last Postback: <%=System.DateTime.Now %>

<asp:UpdatePanel ID="UP1" runat="server">


        Last Update: <%=System.DateTime.Now %>



<input type="button" onclick="$get('UP1').Update(); return false;" />



02/22/2007 11:08 PM by

UpdatePanels update when a control inside them does a post-back, or when a control that is associated with the updatepanel via a trigger does a postback.


So for example, if your button was inside the updatepanel, and you wanted to cause it to postback, you'd just write this JavaScript:

$get('<%=MyButton.ClickId %>').click();

This will cause the button to fire, and the updatepanel it was in (or associated with via a trigger) would update.



Justin-Josef Angel [MVP]
02/23/2007 05:31 AM by
Justin-Josef Angel [MVP]

You can use the server-side ScriptManager.RegisterAsyncPostBackControl so any control event will make the updatepanel refresh.


or (and you didn't here this from me) look at the Javascript code RegisterAsyncPostBackControl produces and use the Sys.WebForms.PageRequestManager.getInstance()._updateControls client-side method.

Naturelly, you should never use javascript private methods. But you can :-)

Ayende Rahien
02/23/2007 07:08 AM by
Ayende Rahien


I need to make a decision on the client side if I would update the panel or not, it is not just clicking on a control and being done with it.

I would hope to avoid using the private methods.

I am already forced to do this for updating cascading drop down from code.

Ayende Rahien
02/23/2007 07:08 AM by
Ayende Rahien


Yes, I know that, but in this case, I have several panels that contains information, the user is updating a record, which should cause all the other updates to be refreshed. I can't register a control as a post back trigger, because the refresh is depending on the input from the user.

The use case for an update panel in this case is: "I want to update this particular section of the page with information."

In this case, there isn't any way to do this short of faking a postback that the update panel will catch. This seems unnatural to me, because there isn't anything there that should be clicked.

Comments have been closed on this topic.