Export (0) Print
Expand All

Using the AJAX Update Panel in SharePoint

Typical Goals

You want to use the AJAX UpdatePanel control on a SharePoint page or in a Web Part even though, by default, this control does not work with these standard SharePoint components because of differences in the postback mechanisms that are used by SharePoint and ASP.NET.

Ff650218.note(en-us,PandP.10).gifNote:
The ASP.NET AJAX UpdatePanel control must change the page’s postback behavior to enable support for asynchronous postbacks and partial rendering. However, in a SharePoint application, these modifications cause a JavaScript error. This is because SharePoint attempts to make a similar change. The SafeScriptManager control corrects the JavaScript problem.

Solution

In Visual Studio, add a reference to Microsoft.Practices.SPG.AJAXSupport.dll. Add a SafeScriptManager control to your page and set the EnableUpdatePanelSupport flag to true. This changes the postback script that is needed for the UpdatePanel control to work in a SharePoint environment. The following code demonstrates how to add a SafeScriptManager control to a page.

<%@ Register 
   Assembly="Microsoft.Practices.SPG.AJAXSupport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8768CCAE1C3C9EB2"
   TagPrefix="spg" 
   Namespace="Microsoft.Practices.SPG.AJAXSupport.Controls" %>

<spg:SafeScriptManager ID="SafeScriptManager" 
                                                   runat="server" 
          EnableUpdatePanelSupport = “True”
                                                   />

<asp:UpdatePanel runat=”Server” id=”MyUpdatePanel”>
 ...
</asp:UpdatePanel>

Usage Notes

You may place several SafeScriptManager controls on your page, and it is allowed to set the EnableUpdatePanelSupport flag on each SafeScriptManager control on your page. However, when there are multiple SafeScriptManager controls on a page, only one of them must set the EnableUpdatePanelSupport flag to true in order to enable the correct postback behavior for the whole page.


Home page on MSDN | Community site

Show:
© 2014 Microsoft