I've tried following this advice for disabling a ScriptManager programmatically, to no avail: http://stackoverflow.com/questions/1057905/disable-scriptmanager-on-certain-pages
StandardScriptManager.ascx:
<%@ control language="vb" autoeventwireup="false" codebehind="StandardScriptManager.ascx.vb" inherits="StandardScriptManager" %>
<h1>StandardScriptManager is visible</h1>
<asp:scriptmanager id="MyScriptManager" runat="server" enablepartialrendering="true" >
<scripts>
<asp:scriptreference path="/Standard/Core/Javascript/script1.js" />
<!-- etc... -->
</scripts>
</asp:scriptmanager>
StandardScriptManager.ascx.vb:
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?