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 (5 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
Did you found this article helpful?
Buy me a coffee :)

Sharepoint , ,

  1. Balakrihnan
    July 7th, 2009 at 14:48 | #1

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

  2. Deepak
    July 7th, 2009 at 15:25 | #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
    July 8th, 2009 at 11:28 | #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
    February 4th, 2010 at 10:04 | #4

    Thans for ur gr8 article. keep it up!

  5. March 15th, 2010 at 14:40 | #5

    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. May 30th, 2010 at 20:26 | #6

    Thanks my friend!
    you saved my life!

    Congratulations!

  7. Tuan Do Thanh
    June 2nd, 2010 at 07:27 | #7

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

  8. diego
    June 17th, 2010 at 01:52 | #8

    two years later, but I only can say

    THANKS
    THANKS
    THANKS
    THANKS
    THANKS

  9. Dan
    August 10th, 2010 at 18:08 | #9

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

  10. Sanjoyan
    August 13th, 2010 at 12:43 | #10

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

  11. Amol
    September 10th, 2010 at 15:05 | #11

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

  12. rob
    October 5th, 2010 at 07:15 | #12

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

  13. Swati Jain
    October 7th, 2010 at 06:20 | #13

    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. October 11th, 2010 at 13:40 | #14

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

  15. Arun
    October 27th, 2010 at 23:47 | #15

    Thank you very much. You saved my time!!

  16. December 25th, 2010 at 11:27 | #16

    Thank you Sir, i saved my lot of days, thank you again

  17. May 31st, 2011 at 12:34 | #17

    Great!!! It works!!!

  18. smartbzs
    July 14th, 2011 at 12:45 | #18

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

  19. Owais
    August 28th, 2011 at 20:15 | #19

    Thanks !ou save lot of my time

  20. Ahmad
    September 17th, 2011 at 11:08 | #20

    Thanks a lot, really helpful.

  21. prajakta
    November 14th, 2011 at 10:22 | #21

    Very Good.really helpful for me.

  22. Vince
    December 13th, 2011 at 00:55 | #22

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

  1. No trackbacks yet.