递归调用form里的所有控件,检查是否是你要有效的控件,如果不是就disabled。
一定要递归,就是调用当前控件的子控件,写一个递归方法就可以了。

解决方案 »

  1.   

    /// <summary>
            /// 控制控件是否可用
            /// </summary>
            /// <param name="page"></param>
            public static void EnableDisableOneControls(System.Web.UI.Control page, bool bFalg)
            {
                int nPageControls = page.Controls.Count;
                for (int i = 0; i < nPageControls; i++)
                {
                    foreach (System.Web.UI.Control control in page.Controls[i].Controls)
                    {
                        if (control.HasControls())
                        {
                            EnableDisableOneControls(control, bFalg);
                        }
                        else
                        {
                            if (control is TextBox)
                                (control as TextBox).Enabled = bFalg;
     
                           if (control is Button)
                                (control as Button).Enabled = bFalg; 
                            if (control is CheckBox)
                                (control as CheckBox).Checked = bFalg;                        if (control is DropDownList)
                                
                                (control as DropDownList).Enabled = bFalg;                        if (control is UserControl)
                                (control as UserControl).e = bFalg;                        if (control is RadioButtonList)
                                (control as RadioButtonList).SelectedIndex = -1;                        if (control is RadioButton)
                                (control as RadioButton).Checked = bFalg;                        if (control is CheckBoxList)
                            {
                                foreach (ListItem item in (control as CheckBoxList).Items)
                                {
                                    item.Selected = bFalg;
                                }
                            }
                        }//if..else 
                    }//foreach 
                }//for 
            }
      

  2.   

    给你一段JS代码
    js
    function getControl()
    {
    var input = document.getElementsByTagName("Input");
    for(var i =0 ; i < input.length; i++)
    {
     if(input[i].type   ==   "checkbox"   &&  input[i].id.indexOf("one") > -1)   //条件当是Checkbox并且ID带有one时
    input[i].disabled == "0"  //使控件无效
    }
    }
      

  3.   

    照5楼的方法可以实现,但是能不能通过判断控件的Text名来设置他有没有效,不然的话很多种类的控件的话,代码很长
      

  4.   


    判断一下就好了.是用id还是用其它的自己看着办
    if(control is TextBox)
    {
          if((control as TextBox).ID== "你要控件id")
             {
                 (control as TextBox).Enabled = false;
             }
    }
      

  5.   

    判断一下就好了.是用id还是用其它的自己看着办 C# codeif(control is TextBox)
    {
          if((control as TextBox).ID== "你要控件id")
             {
                 (control as TextBox).Enabled = false;
             }
    }
    [/Quote]
    我的意思是能否不用判断控件的类型(TextBox或者Button等),而直接利用控件的Text名来设置它的True或False
      

  6.   

    if(control.ID == "你要的id")//服务器端的控件这个id是都有的.因为Control是个基类,但是enable可能没有
    //只能转成相应的控件后才可得到特有的属性
    {
         
    }
      

  7.   

    System.Web.UI.Control这个是个基类(定义由所有 ASP.NET 服务器控件共享的属性、方法和事件)
    他里边的属性有限.你可以查看一下msdn.其它的服务器端控件继承这个类来实现.
    一些特有的属性都是在子类中分别实现的.这就是OO思想