I've spoken about this a few times in my presentations on the topic, but I don't think I ever blogged about it.  Basically to get ASP.NET AJAX to fully with with SharePoint 2007, you need to include some Javascript "fix" code which allows the ASP.NET AJAX to function properly. 

According to Microsoft, the reason for this code is the following "For ASP.NET controls that use the JavaScript _doPostBack() function to commit changes, a regular full-page postback event may occur even when the Web Part is inside an UpdatePanel control. Windows SharePoint Services 3.0 and ASP.NET AJAX cache certain form actions, which can cause a conflict between SharePoint and ASP.NET AJAX. To change this behavior, you must add code to scripts that are running in Windows SharePoint Services 3.0"

Below is the code you'll need to include in your Web Parts.

private void EnsurePanelFix()
{
   if (this.Page.Form != null)
   {
     String fixupScript = @"_spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");
     function _initFormActionAjax()
     {
       if (_spEscapedFormAction == document.forms[0].action)
       {
         document.forms[0]._initialAction = 
         document.forms[0].action;
       }
     }
     var RestoreToOriginalFormActionCore = RestoreToOriginalFormAction;
     RestoreToOriginalFormAction = function()
     {
       if (_spOriginalFormAction != null)
       {
         RestoreToOriginalFormActionCore();
         document.forms[0]._initialAction = document.forms[0].action;
       }
     }";
   ScriptManager.RegisterStartupScript(this, 
     typeof(YOUR_WEBPART), "UpdatePanelFixup", 
     fixupScript, true);
   }
}
 
This code comes straight from Microsoft and you find it at http://msdn2.microsoft.com/en-us/library/bb861877.aspx
I've successfully been using the following code in my web parts without issue (for the life of me, I can't remember where I found it).
 
private void EnsureUpdatePanelFixups()
{
    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(Demo01SimpleWebPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}
So the choice is yours as to which one to use. I've been sticking with the one I've found and have tested pretty thoroughly, but I'd like to think that the MS way is probably more "supported".

Posted in: Sharepoint  Tags: , ,
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Tony Testa's World