Home > Sharepoint > Ajax second postback not working in Sharepoint in UpdatePanel

Ajax second postback not working in Sharepoint in UpdatePanel

October 10th, 2008
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

We have one problem in work, we spend with that two days without any solution, all we found cause some another problem. This is what help us when the page is not making second postback in update panel when the first postback is fired by element in UpdatePanel and refresh only update panels on the page.

Taken 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 could be emitted by a control that uses the UpdatePanel. The following is an example of a very simple method which will fix this issue:


private void EnsureUpdatePanelFixups()
{
  if (this.Page.Form != null)
  {<br />
    string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
    if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
    {
      this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
    }
  }
  ScriptManager.RegisterStartupScript(this, typeof(AjaxUpdatePanelPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}
Share and Bookmark:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • blogmarks
  • DotNetKicks
  • E-mail this story to a friend!
  • Furl
  • Live
  • Reddit
  • Slashdot

Sharepoint , ,

  1. Balakrihnan
    | #1

    Well, Its working fine. Already I had spent lot of time for this.
    Thanks lot….

  2. Deepak
    | #2

    Gr8 article. It really saved my life. Updatepanel was not at all working in arabic version of sharepoint portal. I had decided to leave updatepanel and go for using the basic xmlHttpRequest and xmlHttpResponse objects to make asynchronous callback to codebehind and getting the results in javascript. While I read this article and implemented the code I jumped out of my chair by seeing it working fine.
    Thanks a zillion.
    I started crosschecking the code as to know how exactly it is working.
    I found one optimization that can be done in the code. Only registering this line _spSuppressFormOnSubmitWrapper=true; in client script does the job. Thanks again for writing this article.

  3. Fernando
    | #3

    Thank you!! Its works!!
    Only a question. I have 2 servers with sharepoint. Before this solution, in one of them, ajax did work fine but in other ajax didn’t work due to this problem. What is the diference?

  4. prashant
    | #4

    Thans for ur gr8 article. keep it up!

  1. No trackbacks yet.