我的网页上有三个单选按钮和五个文本框。我想根据收音机选择禁用文本框。这段代码工作正常但是当我检查一个不同的单选按钮时,之前的灰色文本框没有变白。请纠正我,我已经尝试了几种不起作用的方法。
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;
}
}
答案 0 :(得分:3)
如果禁用TextBox但是在启用它时没有将其更改回来,则会将颜色更改为lightgray:
txtEmail.Enabled = true;
txtEmail.BackColor = System.Drawing.Color.White;