如果检查单选按钮,如何为更新面板设置可见的true?

时间:2015-06-07 22:52:59

标签: c# jquery html asp.net

我有2个单选按钮,它们都可以在页面中看到更新面板,但面板中的工具值不同。 P.S:我正在使用一个页面依赖于我网站上的母版页。 当我检查任何单选按钮时,面板不可见!

protected void  Sale_CheckedChanged(object sender, EventArgs e)
{
    if (Sale.Checked)
    {
        UpdatePanel1.Visible = true;
        PriceLabel.Text = " Sale Price:";
    }
}
    protected void  Rent_CheckedChanged(object sender, EventArgs e)
{
        if (Rent.Checked)
    {
        UpdatePanel1.Visible=true;
        PriceLabel.Text = " Rent Price:";
    }
}

3 个答案:

答案 0 :(得分:0)

听起来GUI线程很忙。尝试通过调用Application.DoEvents()强制屏幕更新,例如:

protected void  Sale_CheckedChanged(object sender, EventArgs e)
{
    if (Sale.Checked)
    {
        UpdatePanel1.Visible = true;
        PriceLabel.Text = " Sale Price:";
        Application.DoEvents();
    }
}
    protected void  Rent_CheckedChanged(object sender, EventArgs e)
{
        if (Rent.Checked)
    {
        UpdatePanel1.Visible=true;
        PriceLabel.Text = " Rent Price:";
        Application.DoEvents();
    }
}

DoEvents()将强制处理消息队列中的所有消息。

答案 1 :(得分:0)

您需要为收音机按钮添加值,例如:" 1"或" 2"然后你双击你的RadioButton或RadioButtonList,这应该出现在.cs文件中:

    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (RadioButtonList1.SelectedValue == 1)
    {
        UpdatePanel1.Visible = true;
        PriceLabel.Text = "Text1:";
    }
    else
    {
        UpdatePanel2.Visible = true;
        PriceLabel.Text = "Text2:";
    }
}

因此,如果其中一个被选中,它将显示包含价格文本的框。 这可以更好地做你想做的事。

答案 2 :(得分:0)

private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
               UpdatePanel1.Visible = true;
               PriceLabel.Text = " Sale Price:";

            }
            else
            {
               UpdatePanel1.Visible = true;
               PriceLabel.Text = " Rent Price:";
            }
        }
相关问题