在 ASP.NET 中,如何找到嵌套在 DetailsView 中的 TextBox 的控件 ID,然后再嵌套在 AJAX UpdatePanel 控件中?

发布于 2024-07-27 00:59:23 字数 299 浏览 4 评论 0原文

在 ASP.NET 中,如何找到嵌套在 DetailsView 中的 TextBox 的控件 ID,然后再嵌套在 AJAX UpdatePanel 控件中?

层次结构是:UpdatePanel1 -> dvContentDetail(详细信息视图控件)-> TextBox2

我尝试过类似以下的操作,但只是说找不到该对象:

UpdatePanel1.FindControl("dvContentDetail").FindControl("TextBox2").ClientID

n ASP.NET how do I find the Control ID of a TextBox that is nested within a DetailsView which is then nested in an AJAX UpdatePanel control ?

The heirachy is: UpdatePanel1 -> dvContentDetail (DetailsView Control) -> TextBox2

I have tried something like the following but just says that the object isn't found:

UpdatePanel1.FindControl("dvContentDetail").FindControl("TextBox2").ClientID

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

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

发布评论

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

评论(2

迷鸟归林 2024-08-03 00:59:23

不需要从updatepanel中找到控件,因为这些控件直接可用,所以你的代码将是这样的......

TextBox TextBox2 = (TextBox)dvContentDetail.FindControl("TextBox2");

There is no need to find control from updatepanel, because these controls directly available, so you code will be like this...

TextBox TextBox2 = (TextBox)dvContentDetail.FindControl("TextBox2");
迷乱花海 2024-08-03 00:59:23

您可以尝试类似下面的代码。 但是,如果您知道层次结构不会发生变化,那么最好执行一系列“FindControl”调用。 要发现正确的层次结构,请调试应用程序并搜索控制层次结构。

public static T FindControlRecursiveInternal<T>(Control startingControl, string controlToFindID) where T : Control
{
    if (startingControl == null || String.IsNullOrEmpty(controlToFindID))
        return (T)null;

    Control foundControl = startingControl.FindControl(controlToFindID);
    if (foundControl == null)
    {
        foreach (Control innerControl in startingControl.Controls)
        {
            foundControl = FindControlRecursiveInternal<T>(innerControl, controlToFindID);
            if (foundControl != null)
                break;
        }
    }

    return (T)foundControl;
}

You could try something like the code below. But if you know the Hierarchy is not going to change it would be better to do a series of "FindControl" calls. To discover the correct hierarchy, Debug the app and search through the Control Hierarchy.

public static T FindControlRecursiveInternal<T>(Control startingControl, string controlToFindID) where T : Control
{
    if (startingControl == null || String.IsNullOrEmpty(controlToFindID))
        return (T)null;

    Control foundControl = startingControl.FindControl(controlToFindID);
    if (foundControl == null)
    {
        foreach (Control innerControl in startingControl.Controls)
        {
            foundControl = FindControlRecursiveInternal<T>(innerControl, controlToFindID);
            if (foundControl != null)
                break;
        }
    }

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