Detect when radio button is checked
<p>I have a form build in code behind.</p>

<p>What I am trying to do is detect when a radio button is checked, and when its checked changes.</p>

<p>I have the following</p>

<pre><code>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);
</code></pre>

<p>testEquipment is a instance of a object that stores the some data.</p>

<pre><code>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 });
</code></pre>

<p>I then want to disable the textbox and the requiredfieldvalidator when the radio button is clicked. There is three ie. none, default, other</p>

<p>When other is selected the textbox must become enabled along with the required field validator.</p>

<pre><code>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;
    }
</code></pre>
