Help and Support

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

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

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.

Back to the top

CAUSE

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

Back to the top

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);
            }
        }
    }

Back to the top


APPLIES TO
Microsoft Office SharePoint Server 2007
Microsoft Windows SharePoint Services 3.0

Back to the top

Keywords: 
kbtshoot kbprb kbexpertiseinter KB941955

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.