Disable ScriptManager on certain pages

asp.net, asp.net-ajax, scriptmanager

Solution

Move your <asp:ScriptManager /> to a custom control e.g. MyScriptManager.ascx - the only code in the .ascx file will be the ScriptManager tag - then you can set the Visible property on your custom control to control whether the ScriptManager gets rendered.

<foo:MyScriptManager id="scriptManager" runat="server" Visible="false" />

You could maybe even add a Property to your MasterPage which you could use in your content pages to show / hide the ScriptManager:

// In your master page
public bool ShowScriptManager {get; set;}

// In your master page's Page_Load
private void Page_Load(object sender, EventArgs e) {
    ...
    scriptManager.Visible = ShowScriptManager;
    ...
}

As most of your pages require the ScriptManager, it might be an idea to make it default to true - I think you can do this in your Master Page's constructor of Page_Init method:

public SiteMaster() {
    ...
    ShowScriptManager = true;
    ...
}

// Or alternatively
private void Page_Init(object sender, EventArgs e) {
    ...
    ShowScriptManager = true;
    ...
}

Then, if you've set the MasterType in your content pages:

<%@ MasterType VirtualPath="~/path/to/master/page" %>

You just need to do something like this in content page's Page_Load:

Master.ShowScriptManager = false;

Problem

I have a script manager on my Master page. There are one or 2 content pages that I need to remove the webresourse.axd from, as it is causing issues with other javascript on the page How can I disable the script manager on these pages? The ScriptManager object doesnt appear to have any properties that would seem like they would do the job Is this possible?

Original source