/// <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 }
给你一段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" //使控件无效 } }
/// 控制控件是否可用
/// </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
}
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" //使控件无效
}
}
判断一下就好了.是用id还是用其它的自己看着办
if(control is TextBox)
{
if((control as TextBox).ID== "你要控件id")
{
(control as TextBox).Enabled = false;
}
}
{
if((control as TextBox).ID== "你要控件id")
{
(control as TextBox).Enabled = false;
}
}
[/Quote]
我的意思是能否不用判断控件的类型(TextBox或者Button等),而直接利用控件的Text名来设置它的True或False
//只能转成相应的控件后才可得到特有的属性
{
}
他里边的属性有限.你可以查看一下msdn.其它的服务器端控件继承这个类来实现.
一些特有的属性都是在子类中分别实现的.这就是OO思想