当 ScriptManagerProxy 控件存在时,以编程方式禁用 ScriptManager

发布于 2024-09-05 01:40:05 字数 1975 浏览 5 评论 0原文

我尝试按照此建议以编程方式禁用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2024-09-12 01:40:05

我也无法让它工作,但我今天找到了解决方案。

如果您使用的是 .Net 4.0,则可以使用新的 AjaxFrameworkMode 属性并将其设置为“禁用”。

ScriptManager.AjaxFrameworkMode 属性

使用 AjaxFrameworkMode 属性启用所有 Microsoft Ajax 脚本
文件,禁用所有 Microsoft Ajax 脚本文件,或显式
包括单独的脚本文件。

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

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文