For those of us who use the __doPostBack method in combination with hidden fields to control updatepanel post backs, the latest .Net 4.0 release presents a small problem.   __doPostBack calls without an associated control id no longer cause a full postback when executed from an updatepanel.  Somehow, .Net knows which update panel you execute the __doPostBack call from and in response only updates the associated panel.   Click here for more information on launching post backs directly using JavaScript.

This poses a problem if you have written code that actually needs to launch a full page postback from within an updatepanel.   The work around is pretty simple, though it’s quite annoying to browse through a multi-project solution and find every instance of this issue.


Workaround:

Whenever you want to launch a full page postback using the __dopostback command, you’ll need to include a matching hidden field outside of all update panels.  Here’s a sample:

<asp:UpdatePanel ID=”up1″ runat=”server”>
<ContentTemplate>
<input type=”button” onclick=”__doPostBack(‘cmdDoSomething’, ”);”>
</ContentTemplate>
</asp:UpdatePanel>

<!– Force Full Page Postback Here –>
<input type=”hidden” id=”cmdDoSomething” >

I’m very thankful for FireBug, as I spent about 5 hours using it to track down and resolve this issue.  I’d love to hear from anyone who may know more about underlying changes to AJAX functionality in the new 4.0 Framework.  I’m concerned that there may be other hidden problems arising as I convert more sites over to 4.0.


Kick It on DotNetKicks.com