我已尝试按照此建议以编程方式禁用 ScriptManager,但无济于事: 在某些页面上禁用 ScriptManager
标准脚本管理器.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>
标准脚本管理器.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
为 true,<h1>
则不会显示,但脚本仍会添加到页面中。我怀疑这是因为我在页面的其他地方有 ScriptManagerProxy 对象。
我也试过Me.Controls.Clear()
了Page.Init
,但我明白了
[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
.
有任何想法吗?