Press "Enter" to skip to content

Ajax second postback not working in Sharepoint in UpdatePanel

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);
}

33 Comments

  1. Balakrihnan
    Balakrihnan July 7, 2009

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

  2. Deepak
    Deepak July 7, 2009

    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
    Fernando July 8, 2009

    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
    prashant February 4, 2010

    Thans for ur gr8 article. keep it up!

  5. Arnold Boersma
    Arnold Boersma March 15, 2010

    Thanks this solved our issue! Strange thing that we didn’t see the issue on our dev and test environment but only on production, we couldn’t find out the differences.

  6. Luiz Dias
    Luiz Dias May 30, 2010

    Thanks my friend!
    you saved my life!

    Congratulations!

  7. Tuan Do Thanh
    Tuan Do Thanh June 2, 2010

    I just can say only 4 words “You save my life” . Thanks you

  8. diego
    diego June 17, 2010

    two years later, but I only can say

    THANKS
    THANKS
    THANKS
    THANKS
    THANKS

  9. Dan
    Dan August 10, 2010

    Thanks a lot… i spent a lot of time trying to solve this issue.

  10. Sanjoyan
    Sanjoyan August 13, 2010

    Thanks a lot … I was about to give up !!!

  11. Amol
    Amol September 10, 2010

    Really excellent solution……….Worked for me too and saved my lot of time.

  12. rob
    rob October 5, 2010

    I dont know what i would have done without this article, thanks a million!!!

  13. Swati Jain
    Swati Jain October 7, 2010

    This is great… helped me a lot. But, I am facing a problem in IE8. This works fine in IE 6,7 but, sometimes starts giving error in IE8. The error I am getting in IE8 is –
    Message: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404
    Line: 4723
    Char: 21
    Code: 0
    URI:

    Any ideas why this might be happening

  14. Martin M?lek
    Martin M?lek October 11, 2010

    @Swati Jain
    Hi Swati, is it possible to have a look at that problem? Do you have public url of that project?

  15. Arun
    Arun October 27, 2010

    Thank you very much. You saved my time!!

  16. smartbzs
    smartbzs July 14, 2011

    You anyone please share the code i.e. how you people has done this i am facing alot of issues in sharepoint 2010.

  17. Owais
    Owais August 28, 2011

    Thanks !ou save lot of my time

  18. Ahmad
    Ahmad September 17, 2011

    Thanks a lot, really helpful.

  19. prajakta
    prajakta November 14, 2011

    Very Good.really helpful for me.

  20. Vince
    Vince December 13, 2011

    Thank you very much. This was very helpful to me!

  21. Dhinagaran
    Dhinagaran July 18, 2012

    THANKS
    BROTHER

  22. Anil
    Anil September 24, 2012

    Many Many Many.. thanks!! saved a lot of time!

  23. Hodgson
    Hodgson October 22, 2012

    Wow, this solved my postback issue after binarywrite. THANKS!

  24. ravi ranjan
    ravi ranjan January 2, 2013

    great help. But not working in IE.
    Anybody have solution for IE.

  25. basith
    basith May 18, 2013

    wer to put the function private void EnsureUpdatePanelFixups()
    and wer to place the script
    ?

  26. Jose
    Jose August 21, 2013

    Same question
    “were to put the function private void EnsureUpdatePanelFixups()
    and were to place the script
    ?”

    i have a lot of Ajax Functions , do i need call it every single time?

  27. Hiren Joshi
    Hiren Joshi November 6, 2013

    Thanks a lottttttttttttttttttttttttt.

  28. Aravinthan Babu
    Aravinthan Babu December 10, 2013

    Thanks a lot………….

  29. Martin M?lek
    Martin M?lek December 23, 2013

    Sorry, but I don’t work with Sharepoint anymore. You can use reflection to find where the function EnsureUpdatePanelFixups is and where you need to override that. With the javascript, you can put it at the end of the template, or if you are using HTML5, you can change the first line to:

  30. mohammad
    mohammad February 1, 2014

    hi,
    where should i exactly call this method ? EnsureUpdatePanelFixups();
    in page load !IsPostBack or else where?

    what is AjaxUpdatePanelPart ? your page name?

Leave a Reply

Your email address will not be published. Required fields are marked *