当 ScriptManagerProxy 控件存在时,以编程方式禁用 ScriptManager
我尝试按照此建议以编程方式禁用 ScriptManager,但无济于事: 在某些页面上禁用 ScriptManager
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
当 DisableAllScripts
为 true 时,
不会显示,但脚本仍会添加到页面中。我怀疑这是因为我在页面的其他地方有 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
。
有什么想法吗?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也无法让它工作,但我今天找到了解决方案。
如果您使用的是 .Net 4.0,则可以使用新的 AjaxFrameworkMode 属性并将其设置为“禁用”。
ScriptManager.AjaxFrameworkMode 属性
ScriptManager1.AjaxFrameworkMode = AjaxFrameworkMode.Disabled
希望能帮助那些像我一样最终来到这里的人..
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
ScriptManager1.AjaxFrameworkMode = AjaxFrameworkMode.Disabled
Hope that helps someone who ends up here as I did..