У меня есть встроенный код.Обнаруживать, когда установлен переключатель радиосвязи
То, что я пытаюсь сделать, это обнаружить, когда установлен переключатель, и когда его проверили.
У меня есть следующие
RadioButton radio = new RadioButton() { ClientIDMode = System.Web.UI.ClientIDMode.Static, AutoPostBack=true, ID = "rbOther" + testEquipment.Id, GroupName = "grp" + testEquipment.Id, Checked = false };
radio.CheckedChanged += new EventHandler(radio_CheckedChanged);
testEquipment является экземпляром объекта, который хранит некоторые данные.
tdBrandName.Controls.Add(new TextBox() { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = "txtBrandName" + testEquipment.Id, Text = serviceStationTestEquipment != null ? serviceStationTestEquipment.BrandName : string.Empty, Width = new Unit(300), Enabled = serviceStationTestEquipment != null ? serviceStationTestEquipment.Other : false });
tdBrandName.Controls.Add(new RequiredFieldValidator() { Display = ValidatorDisplay.Dynamic, ControlToValidate = "txtBrandName" + testEquipment.Id, Text = "Required field", ErrorMessage = "Test Equipment Tab: Field is required", CssClass = "validationerror", Enabled = serviceStationTestEquipment != null ? serviceStationTestEquipment.Other : false, ID = ID = "reqValidator" + testEquipment.Id });
Затем я хочу отключить текстовое поле и необходимый идентификатор при нажатии на переключатель. Существует три то есть. none, default, other
Когда выбрано другое, текстовое поле должно включаться вместе с обязательным полем проверки подлинности.
void radio_CheckedChanged(object sender, EventArgs e)
{
RadioButton check = sender as RadioButton;
if (check == null)
return;
string Id = check.ID.Replace("rbOther", "");
TextBox text = check.Parent.Parent.FindControl(string.Format("txtBrandName{0}", Id)) as TextBox;
text.Enabled = check.Checked;
RequiredFieldValidator validator = check.Parent.Parent.FindControl(string.Format("reqValidator{0}", Id)) as RequiredFieldValidator;
validator.Enabled = check.Checked;
}
Так как же я тогда отключу RequiredFieldValidator? – Armand
См. Мой обновленный ответ. –
ОК еще один вопрос, похоже, этот код не выполняется. Когда я использую firebug и добавляю точку останова к скрипту, он не останавливается на точке останова. Разве этот код не должен выполняться, как на странице, готовой или что-то фактически добавить клик к элементу управления? – Armand