Disable ScriptManager on specific pages

I have a script manager on my main page. There is one or two content pages that I need to remove webresourse.axd, as this causes problems with other javascript on the page

How to disable script manager on these pages?

The ScriptManager object has no properties that look like they were doing work

Is it possible?

+4
source share
4 answers

Move your <asp: ScriptManager /> to a custom control, for example. MyScriptManager.ascx - the only code in the .ascx file will be the ScriptManager tag - then you can set the Visible property to your user control to control whether ScriptManager will be processed.

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

Perhaps you can even add a Property to your MasterPage, which you could use on your content pages to show / hide the ScriptManager:

 // In your master page public bool ShowScriptManager {get; set;} // In your master page Page_Load private void Page_Load(object sender, EventArgs e) { ... scriptManager.Visible = ShowScriptManager; ... } 

Since ScriptManager is required for most of your pages, the idea may be to set the default value to true - I think you can do this in your main page constructor of the Page_Init method:

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

Then, if you installed MasterType on your content pages:

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

You just need to do something like this on the Page_Load content page:

 Master.ShowScriptManager = false; 
+7
source

You can also put the script manager in the ContentPlaceHolder,

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

and on the pages that you want to delete, specify the asp: Content tag on 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> 
+4
source

For those who end here and still cannot get it to work with UserControl ...

If you are using .Net 4.0, you can use the new AjaxFrameworkMode property and set it to Disabled.

ScriptManager.AjaxFrameworkMode Property

Hope this helps someone!

+1
source

I would use nested master pages. The main wizard, which has markup with an additional holder for the content place where the script manager will be. Then two versions of the nested wizard, one with the script manager and one without it. And your pages use the corresponding nested homepage.

I leave the text below, so the comments make sense, but this does not work ...

How about this:

-Please add the application to your web interface with a list of URIs that you do not want to have a script manager.
-In the page_init event handler of the wizard, get this collection and test to see if the current page request is in the list. If so, remove the scriptmanager from the wizard's control collection.

those. in the code of the main page:

 Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If DirectCast(Page, System.Web.UI.Page).AppRelativeVirtualPath = "~/Test.aspx" Then Me.Controls.Remove(Me.FindControl("ScriptManager1")) End If End Sub 

Note. There is a great danger in what you do. If there are any update panels on the main page or on any of the pages on which you delete the manager, they will bomb. You can scroll through the master collection of the wizard and the page in the main file of the wizard and check all the update panels. Although, I'm not sure what you would do if you found them. Removing them will likely result in the removal of any content in them. In the best case, you can either 1) not delete the script Manager if the update panel is found, or 2) Configure an error.

0
source

All Articles