Disable ScriptManager programmatically when ScriptManagerProxy controls are present
I've tried following this advice for disabling a ScriptManager programmatically, to no avail: 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 c开发者_JAVA技巧ontext 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?
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..
精彩评论