Forcing a Partial Postback from JavaScript

Published 18 January 08 11:26 AM | Tom Wardill

In this situation, you would like to cause a postback, notifying the server of a change in a hidden fields contents. 

 function PartialPB(someValue)
        {
            var hidden = document.getElementById(hiddenClientId);
            hidden.value = someValue;
            __doPostBack('<%= TaskUpdatePanel.ClientID %>', '');
        }

Wrap the hidden field in an update panel (TaskUpdatePanel in this case):

<asp:UpdatePanel ID="TaskUpdatePanel" runat="server" UpdateMode="Always"><ContentTemplate>
   <asp:HiddenField ID="sampleHiddenField" runat="server" Value="" />
</ContentTemplate></asp:UpdatePanel>

 

This should work. The important part is the UpdatePanel ID as the first argument in the __doPostBack(). This will set the target to be the UpdatePanel, and cause a Partial Postback rather than a full. 

Comments

# Luke Smith said on February 8, 2008 08:12 PM:

I'm suprised the functionality isn't built into the MS Ajax framework itself, it seems like an obvious thing for people to want to do. I've needed it once or twice and discovered this solution.

One thing I also hate is having to put javascript in the page itself, but also hate having to hardcode ctl00_blah_blah_mycontrol in an external javascript file (just incase it changes at some point). I experimented with a creating a jsx page a while back, where the jsx page was parsed on request to the page and you could put things like <%= MyControl.ClientID %> in it. Maybe i should dig it out and post it on my blog.

Leave a Comment

(required) 
(required) 
(optional)
(required)