Share via


AJAX Postbacks not working with any masterpage other than default.master

Consider the following scenario:

You develop a webpart using AJAX that works fine with SharePoint default masterpage (default.master), but as soon as you use a different masterpage, for example blueband.master, asynchronous postbacks do not work anymore.

The reason is because in those masterpages, SPWebPartManager server tag is outside of <form></form> tags. To workaround this, you can change the location of the ScriptManager tag and put it inside the <form> tag:

 <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
<WebPartPages:SPWebPartManager runat="server"/>

Important: if you modify a masterpage provided with SharePoint, such as the blueband.master, you must create a copy of it, modify the copy and update the site to use the new one, don't forget this is not supported to modify SharePoint default files (except a very few ones).

Unfortunately this modification has a major drawback, the page title is broken (it is replaced with "\r\n\t") after the first AJAX postback. Fortunately, it can be fixed very easily with the following piece of code that you can add in your webpart:

protected override void OnLoad(EventArgs e)

{

    if (this.Page.IsPostBack)

        this.Page.Title = String.Empty;

}

It seems SharePoint checks the page title, and set it when it is empty.

If your postbacks are even not working with default masterpage, this article probably does not apply to you, take a look at this kb: https://support.microsoft.com/kb/941955.

You can find general information on AJAX integration with SharePoint and practical example on this page: https://msdn.microsoft.com/en-us/library/bb861881.aspx.

Comments

  • Anonymous
    August 15, 2011
    Awesome! Great tip on the page title thing. Solved the problem for us. Thanks. By the way, this page title thing does not manifest itself in Chrome, but does in IE 8 (this is with SharePoint 2010).

  • Anonymous
    April 13, 2012
    Nice Blog Post, thanks

  • Anonymous
    July 18, 2012
    I created visual webpart using 2010.  I implemented update panel. I am facing exactly same problem as you discussed here. Update panel works fine with default.master page but with custom master page it does not. I changed my custom master page as per your solution. But unfortunately, it does not solve my problem. Can you able to help me what could be the problem?