我的网页中有三个单选按钮和五个文本框。我想根据单选框选择禁用文本框。这段代码工作正常,但是当我检查一个不同的单选按钮时,之前的灰色文本框没有变白。请纠正我,我尝试了几种方法都不起作用。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtName.Enabled = false;
txtTitle.Enabled = false;
txtOrganization.Enabled = false;
txtPhone.Enabled = false;
txtEmail.Enabled = false;
}
if (rdPhone.Checked == true)
{
txtName.Enabled = true;
txtName.Focus();
txtTitle.Enabled = true;
txtOrganization.Enabled = true;
txtPhone.Enabled = true;
txtEmail.Enabled = false;
txtEmail.BackColor = System.Drawing.Color.LightGray;
}
if (rdEmail.Checked == true)
{
txtName.Enabled = true;
txtName.Focus();
txtTitle.Enabled = true;
txtOrganization.Enabled = true;
txtPhone.Enabled = false;
txtPhone.BackColor = System.Drawing.Color.LightGray;
txtEmail.Enabled = true;
}
if (rdDoNotContact.Checked == true)
{
txtName.Enabled = false;
txtName.BackColor = System.Drawing.Color.LightGray;
txtTitle.Enabled = false;
txtTitle.BackColor = System.Drawing.Color.LightGray;
txtOrganization.Enabled = false;
txtOrganization.BackColor = System.Drawing.Color.LightGray;
txtPhone.Enabled = false;
txtPhone.BackColor = System.Drawing.Color.LightGray;
txtEmail.Enabled = false;
txtEmail.BackColor = System.Drawing.Color.LightGray;
}
}