Webpart and AJAX – second postback not working in UpdatePanel?

I successfully add a webpart with UpdatePanel. However the second post back doesn’t seem to trigger? Why?

Excerpt from Mike Ammerlaan’s Blog

Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:

<script type=’text/javascript’>_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;</script>

This script may be directly embedded in the page. Or write a function like this:

private void EnsureUpdatePanelFixups()
if (this.Page.Form != null)
string formOnSubmitAtt = this.Page.Form.Attributes[“onsubmit”];
if (formOnSubmitAtt == “return _spFormOnSubmitWrapper();”)
this.Page.Form.Attributes[“onsubmit”] = “_spFormOnSubmitWrapper();”;
ScriptManager.RegisterStartupScript(this, typeof(UpdatePanel), “UpdatePanelFixup”, “_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;”, true);

This solves the second post back problem.

This entry was posted in Webpart and tagged , . Bookmark the permalink.

5 Responses to Webpart and AJAX – second postback not working in UpdatePanel?

  1. Ketan says:


    Did you make any changes to your wss web.config file?

  2. Anonymous says:

    Man….u made my day…was stuck on this for so long…thnx fr the workaround..godbles

  3. Saksham says:

    Mike u made my day…was stuck badly…thnx a lot

  4. JamesM says:

    This also seems to happen with normal ASP.NET Webparts, I have a webpart which using registerstartupscript executes a javascript method passing in “test”.

    The JS method then does a confirm(“click OK or cancel”), if user clicks OK it gets clientid of a hidden textbox and puts the value into the textbox.

    Next line of the JS then does a __dopostback(“myUpdatePanel”), this then goes into my page load for my usercontrol inside webpart, and then if textbox.length > 0 it does a label.text = “your message was: ” & hiddentext.text and then modalpopup.show.

    For some reason the modal popup wont show until I click another button which causes a postback. This seems the same second postback issue you refer to.

    Any Ideas?

  5. Asfand says:

    doesn’t work in my case man, dont know whyyyyyyyyyyyy.
    i have been looking ans against this problem but didn’t find out solution yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s