Take the 2-minute tour ×

I've tried following this advice for disabling a ScriptManager programmatically, to no avail: http://stackoverflow.com/questions/1057905/disable-scriptmanager-on-certain-pages


<%@ control language="vb" autoeventwireup="false" codebehind="StandardScriptManager.ascx.vb" inherits="StandardScriptManager" %>
<h1>StandardScriptManager is visible</h1>
<asp:scriptmanager id="MyScriptManager" runat="server" enablepartialrendering="true" >
            <asp:scriptreference path="/Standard/Core/Javascript/script1.js" />
            <!-- etc... -->


Partial Public Class StandardScriptManager
    Inherits System.Web.UI.UserControl

    Private _ScriptManager As ScriptManager

    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If DisableAllScripts Then
            Me.Visible = False
        End If
    End Sub

End Class

When DisableAllScripts is true, the <h1> doesn't show up, but the scripts are still added to the page. I suspect this is because I have ScriptManagerProxy objects elsewhere on the page.

I've also tried Me.Controls.Clear() in Page.Init, but I get this

[InvalidOperationException: Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.]
   System.Web.UI.ScriptManager.get_IPage() +372796
   System.Web.UI.ScriptManager.OnPageInitComplete(Object sender, EventArgs e) +13
   System.Web.UI.Page.OnInitComplete(EventArgs e) +8699478
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +467

It's maddening that there's not a straightforward way to disable the ScriptManager; the control has no Enabled property, and you can't set ScriptManager.Visible=False.

Any ideas?

share|improve this question

1 Answer 1

I could not get this to work either but I found a solution today.

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

ScriptManager.AjaxFrameworkMode Property

Use the AjaxFrameworkMode property to enable all Microsoft Ajax script files, to disable all Microsoft Ajax script files, or to explicitly include individual script files.

ScriptManager1.AjaxFrameworkMode = AjaxFrameworkMode.Disabled

Hope that helps someone who ends up here as I did..

share|improve this answer

Your Answer


