Share via


How to: Use the Safe Script Manager to Provide AJAX Support to Web Parts

The following procedure demonstrates how to add the safe script manager. You can either do this in code or include it on a custom master page.

To add the safe script manager

  1. In Visual Studio, add a reference to Microsoft.Practices.SPG.AJAXSupport.dll.

  2. Create an ASP.NET Web Part. Override the CreateChildControls method and add an instance of the SafeScriptManager class to the Web Part's Controls collection. The following code shows how to do this.

    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    if (this.ControlMode == SPControlMode.Display)
    {
    this.Controls.Add(new SafeScriptManager());
    
              // Add controls that require ScriptManager instance to
              // be on page.
    }
    }
    
  3. An alternative to step 2 is to insert the Microsoft.Practices.SPG.AjaxSupport.Controls.SafeScriptManager control into an ASCX file that is included in your Web Part. The following XML shows how to do this.

    <%@ 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" 
    
                                                       />
    

Home page on MSDN | Community site