我尝试按照以下建议以编程方式禁用ScriptManager,但没有成功:
在某些页面上禁用ScriptManagerStandardScriptManager.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
当
DisableAllScripts
为真时,<h1>
不会显示,但脚本仍然添加到页面中。我怀疑这是因为页面上有其他ScriptManagerProxy对象。我还尝试在
Page.Init
中使用Me.Controls.Clear()
,但我得到了以下结果。[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
真是令人沮丧,没有一种直接的方法可以禁用ScriptManager;该控件没有Enabled
属性,也无法设置ScriptManager.Visible=False
。
有什么想法吗?