Help and Support

Article ID: 941955 - Last Review: October 10, 2007 - Revision: 1.1

A Web Part that contains an ASP.NET AJAX 1.0 UpdatePanel control that uses the _doPostBack() function does not work when the URL of the hosting SharePoint Web site contains international characters

Expand all | Collapse all

SYMPTOMS

Consider the following scenario:
  • You use the Microsoft AJAX 1.0 Control toolkit for Microsoft ASP.NET or the AJAX 1.0 Extensions for ASP.NET to create a custom Web Part for a Microsoft Office SharePoint Server 2007 Web site or for a Microsoft Windows SharePoint Services 3.0 Web site.
  • The custom Web Part contains an UpdatePanel control that includes a _doPostBack() function, such as a LinkButton control.
  • You add the custom Web Part to a SharePoint Services 2007 Web site or to a Windows SharePoint Services 3.0 Web site. The URL of the Windows SharePoint Services 3.0 Web site or the SharePoint Server 2007 Web site contains international characters or language-specific characters.
  • You visit the Windows SharePoint Services 3.0 Web site or the SharePoint Server 2007 Web site. Then, you try to update selected content in the Web Part.
In this scenario, a regular postback request occurs instead of an asynchronous ASP.NET AJAX postback request.

CAUSE

This issue occurs because both Windows SharePoint Services and ASP.NET AJAX cache some types of form actions. Therefore, conflicts may occur.

WORKAROUND

To work around this issue, use code that resembles the following example to add an UpdatePanel control to a Web Part in SharePoint Server 2007 or in Windows SharePoint Services 3.0.
 private void EnsureUpdatePanelFixups()
        {
               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;
    }
}
The following code is an example of a Web Part that includes the previous UpdatePanel control. Additionally, the EnsureUpdatePanelFixups method is used to register the Script Manager control in the Web Part.
 public class AjaxUpdatePanelPart : WebPart
    {
        private Label label;
        private TextBox textBox;
        protected override void  CreateChildControls()
        {
            base.CreateChildControls();
            this.EnsureUpdatePanelFixups();
            UpdatePanel up = new UpdatePanel();
            up.ID = "UpdatePanel1";
            up.ChildrenAsTriggers = true;
            up.UpdateMode = UpdatePanelUpdateMode.Conditional;
            this.Controls.Add(up);
            this.textBox = new TextBox();
            this.textBox.ID = "TextBox";
            up.ContentTemplateContainer.Controls.Add(this.textBox);
            this.label = new Label();
            this.label.Text = "Enter your name.";
            up.ContentTemplateContainer.Controls.Add(this.label);
            LinkButton button = new LinkButton();
            button.Text = "Say Hello";
            button.ID = "HelloButton";  // Some controls need an ID to make them work with AJAX postbacks.
            button.Click += new EventHandler(HandleButtonClick);
            up.ContentTemplateContainer.Controls.Add(button);
        }
        private void HandleButtonClick(object sender, EventArgs eventArgs)
        {
            this.label.Text = "Hello " + this.textBox.Text;
        }
        private void EnsureUpdatePanelFixups()
        {
               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(AjaxUpdatePanelPart), "UpdatePanelFixup", fixupScript, true);
            }
        }
    }

APPLIES TO
  • Microsoft Office SharePoint Server 2007
  • Microsoft Windows SharePoint Services 3.0
Keywords: 
kbtshoot kbprb kbexpertiseinter KB941955

Article Translations