UserControl 内用户控件中的 ScriptManager

发布于 2024-08-29 16:14:36 字数 318 浏览 1 评论 0原文

我有一个 asp.net 用户控件 userControl1.ascx 和另一个用户控件 userControl2.ascx。 userControl2 位于 userControl1 内部。 userControl1 位于 UpdatePanel 控件内。 userControl2 中有一个按钮,然后我想在按下时进行正常的回发。我想使用 ScriptManager.RegisterPostBackControl(button)。我在母版页上有一个 ScriptManager。我不知道如何访问 userControl2 中的 ScriptManager 来注册 Page_Load 事件中的按钮。那么,我该怎么做呢?

I have an asp.net user control, userControl1.ascx, and another user control, userControl2.ascx. userControl2 is inside userControl1. userControl1 is inside an UpdatePanel control. userControl2 has a button in it then I want to have do a normal post back when pushed. I want to use ScriptManager.RegisterPostBackControl(button). I have a ScriptManager on a master page. I don't know how to access the ScriptManager in userControl2 to register the button in the Page_Load event. So, How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

等数载,海棠开 2024-09-05 16:14:36

您可以使用递归 FindControl 方法找到脚本管理器。这不是最佳实践,但它可以完成工作。这并不是一个很好的方法。

var scriptManager = FindControl(Page, "IdOfScriptManager"); 

public static Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id)
        {
            return root;
        }

        foreach (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if (t != null)
            {
                return t;
            }
        }

        return null;
    }

You can find the script manager by using a recursive FindControl method. This is not best practice but it will get the job done. The is not really a pretty way to do this.

var scriptManager = FindControl(Page, "IdOfScriptManager"); 

public static Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id)
        {
            return root;
        }

        foreach (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if (t != null)
            {
                return t;
            }
        }

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