Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable ScriptManager on certain pages

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?

like image 713
ChrisCa Avatar asked Dec 18 '22 07:12

ChrisCa


2 Answers

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;
like image 122
Ian Oxley Avatar answered Jan 02 '23 17:01

Ian Oxley


You could also put the script manager into a ContentPlaceHolder,

<asp:ContentPlaceHolder ID="cph_ScriptManager" runat="server"></asp:ContentPlaceHolder>
    <asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
</asp:ContentPlaceHolder>

and on the pages you want to remove it , have a asp:Content tag point at it, and it will remove it from the page:

<asp:Content ID="content_SM_Overrride" ContentPlaceHolderID="cph_ScriptManager" runat="server">
<!-- ScriptManager Not Needed on this ASPX  -->
</asp:Content>
like image 37
BigBlondeViking Avatar answered Jan 02 '23 17:01

BigBlondeViking