Peter Sullivan – SharePoint, SQL Server and .NET Learnings


AJAX Update Panels and SharePoint
13 June, 2008, 6:17 pm
Filed under: SharePoint | Tags:

If you have added an AJAX UpdatePanel to a control or webpart inside of SharePoint, you will become very frustrated when you find that the second postback does not work. This is due to the way SharePoint wraps buttons.

Mike Ammerlaan has an example of this problem and some additional information about ASP.NET AJAX with SharePoint.

Basically, the workaround is adding an additional function to your code page that alters the _spFormOnSubmitWrapper and the _spFormOnSumitWrapper (example in C#):

private void EnsureUpdatePanelFix()
{
   
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(CompanyRegistration),
       
“UpdatePanelFixup”,
       
“_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;”,
       
true);
}

Make sure that you change the typeof(CompanyRegistration) to reflect the name of your class.

Next, override the CreateChildControls method and add a call to the EnsureUpdatePanelFix() method: 

 

protected override void CreateChildControls()
{
   
base.CreateChildControls();
    EnsureUpdatePanelFix();

}

And that’s it. Problem solved.

1 Comment so far
Leave a comment

Big thanks! Works for me.

Comment by Konrad




Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>