0

我的网页中有三个单选按钮和五个文本框。我想根据单选框选择禁用文本框。这段代码工作正常,但是当我检查一个不同的单选按钮时,之前的灰色文本框没有变白。请纠正我,我尝试了几种方法都不起作用。

 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;

        }
    }
4

1 回答 1

3

如果禁用 TextBox,则将颜色更改为浅灰色,但启用时不会将其更改回:

txtEmail.Enabled = true;
txtEmail.BackColor = System.Drawing.Color.White;
于 2013-07-16T22:32:04.943 回答