我試圖禁用一堆JavaScript控件(以便它們回發值)。除了我的單選按鈕,所有的控件都能正常工作,因爲它們失去了價值。在通過遞歸函數調用以禁用所有子控件的下面的代碼中,第二個else(else if(控件是RadioButton
))從未被擊中,並且RadioButton控件被識別爲Checkbox
控件。使用javascript禁用asp.net單選按鈕
private static void DisableControl(WebControl control)
{
if (control is CheckBox)
{
((CheckBox)control).InputAttributes.Add("disabled", "disabled");
}
else if (control is RadioButton)
{
}
else if (control is ImageButton)
{
((ImageButton)control).Enabled = false;
}
else
{
control.Attributes.Add("readonly", "readonly");
}
}
兩個問題:
1.如何識別控制是一個單選按鈕?
2.如何禁用它以便將其值回傳?