c# - 通过 clientID 获取控制权

标签 c# controls repeater clientid

我解析了 Repeater Item 控件的客户端 ID,我想在其他命令中使用它, 我怎么不能通过他的客户 ID 获得控制权?

TextBox TB = FindControl...?

最佳答案

您是否要查找中继器内的文本框?如果是这样,您可以使用下面的方法,该方法基于控件的 ID 进行搜索 - 您可以修改它以改为基于控件的 clientID 进行检查。

  public static System.Web.UI.Control FindControlIterative(System.Web.UI.Control root, string id)
    {
        System.Web.UI.Control ctl = root;
        var ctls = new LinkedList<System.Web.UI.Control>();

        while (ctl != null)
        {
            if (ctl.ID == id)
                return ctl;
            foreach (System.Web.UI.Control child in ctl.Controls)
            {
                if (child.ID == id)
                    return child;
                if (child.HasControls())
                    ctls.AddLast(child);
            }
            if (ctls.First != null)
            {
                ctl = ctls.First.Value;
                ctls.Remove(ctl);
            }
            else return null;
        }
        return null;
    }

关于c# - 通过 clientID 获取控制权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3934097/

相关文章:

c# - 数据绑定(bind)中继器使中继器加载所有项目两次

c# - Repeater DataBound 事件中的匿名类型

c# - 编码 IDispatch 时出现 COM Interop 灾难性故障 (0x8000FFFF)

c# - 在 linq 'select new object {

c# - C#中的字符串有多长?

c# - ControlPaint.DrawBorder().....但是更厚?

c# - 使用 Form Resize 调整控件大小

c# - 获取 Application_Start 中的当前应用程序物理路径

WinForms 的 iPhone UI 控件

c# - 将事件处理程序添加到中继器中的用户控件