Trigger UpdatePanel via Client Side Javascript

Cristian Merighi () 0.00

ClientAsyncPostBackTrigger is a simple UpdatePanelControlTrigger implementation which permits to trigger un ASP.NET AJAX UpdatePanel just by writing pure javscript client-side code.
This article is obsolete. Some functionalities might not work anymore. Comments are disabled.

I think that this article will result an useful one: it's about triggering an UpdatePanel using client-side (javascript) code. Independently from controls or whatever else, just pure runtime code!

I've been extending the System.Web.UI.UpdatePanelControlTrigger which comes with the ASP.NET AJAX 1.0 package in a "tricky" way.
The core of what I did is pretty straightforward: it's about adding at runtime a Button instance to the UpdatePanel ContentTemplate and triggering its postback client reference.

class diagram

Here's a bit of code which shows how to use it in a common scenario:

<asp:ScriptManager runat="server" ID="sm" EnablePartialRendering="true">

<asp:UpdatePanel runat="server" ID="upd" UpdateMode="Conditional">
        <pacem:ClientAsyncPostBackTrigger ClientTriggerFunction="doTrigger"  />
        [<asp:Label runat="server" ID="lbl" />]

<asp:HiddenField runat="server" ID="hid" />

<script type="text/javascript">
    var iter = 0;
    function preTrigger(v){
        iter += v;
        $get("<%=hid.ClientID %>").value = iter;

<a href="javascript:preTrigger(1);">click to trigger up!</a>
<a href="javascript:preTrigger(-1);">click to trigger down!</a>

...and the dummy server-side one:

void Page_Load(object o, EventArgs e)
    if (IsPostBack) lbl.Text = "postback response: " + hid.Value.ToString();

Just a screenshot to witness the correct functioning:


The class code can be downloaded from the link below.

zip file « download code

Take care. Bye.


  • Re: Trigger UpdatePanel via Client Side Javascript

    Luca Thursday, November 08, 2007 0.00

    L'idea è molto buona, ma se non sbaglio la routine Inizialize() di cui tu fai l'override è dichiarata Protected Friend nella classe UpdatePanelTrigger, quindi non viene mai eseguita!

  • Re: Trigger UpdatePanel via Client Side Javascript

    CMerighi Thursday, November 08, 2007 0.00

    ...Sbagli. ;) Contrariamente a quanto molti pensano, Protected Friend (o protected internal in C#) non significa Protected <del>AND</del> Friend bensì Protected <b>OR</b> Friend! Percui il membro così marchiato è visibile <b>SIA</b> da parte delle classi che sono impacchettate nello stesso assembly (guarda infatti come <i>Initialize()</i> viene richiamato nel metodo <i>InsertItem</i> della classe <i>UpdatePanelTriggerCollection</i>) <b>SIA</b> da parte delle classi che ereditano dall'oggetto che contiene tale membro...




Cristian Merighi facebook twitter google+ youtube

Latest articles

Top rated


Where am I?


Cristian Merighi facebook twitter google+ youtube

I'm now reading