我写服务器控件时这种他是怎么做到的?请高手帮下忙

解决方案 »

  1.   

    RequiredFieldValidator这控件的这个属性 ControlToValidate是如何做到只显示textbox的
    在设计窗口里选中这控件的时候旁边的属性他只会把textbox的ID显示出来怎么做到的?
      

  2.   

    你说的是遍历页面找TextBox的ID吗??
    这样可以:        foreach (Control oControl in this.Controls)
            {
                if (oControl.GetType() == typeof(HtmlForm))
                {
                    foreach (Control item in oControl.Controls)
                    {
                        if (item.GetType() == typeof(TextBox))
                        {
                            ((TextBox)item).ReadOnly = true;   //得到所有的TextBox,设为只读
                        }
                    }
                }
            }
      

  3.   

    通过reflector反编译看看控件属性,
    遍历页面控件判断类型只是一种可能
    foreach (Control control in this.Form.Controls)      
    {            
    if (control is System.Web.UI.WebControls.TextBox)      
    {      TextBox txt = (TextBox)control;       }       
    }
      

  4.   

    写一个服务器控件,有一个属性是来绑定页面上的按钮的,我怎么把这个属性在设计下面选择只显示botton的ID