Tuesday, February 23, 2010

Ajax second postback not working in Sharepoint in UpdatePanel

We have one problem in work, we spend with that a day 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;

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 Sub EnsureUpdatePanelFixups()
        If Me.Page.Form IsNot Nothing Then
            Dim formOnSubmitAtt As String = Me.Page.Form.Attributes("onsubmit")
            If formOnSubmitAtt = "return _spFormOnSubmitWrapper();" Then
                Me.Page.Form.Attributes("onsubmit") = "_spFormOnSubmitWrapper();"
            End If
        End If
        ScriptManager.RegisterStartupScript(Me, GetType(UpdatePanel), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", True)
    End Sub

Mohammed AlShafe'i

No comments:

Post a Comment