如果单选按钮被选中,我如何将更新面板设置为可见true ?

本文关键字:设置 true 更新 单选按钮 如果 | 更新日期: 2023-09-27 17:53:58

我有2个单选按钮,它们都应该在页面中显示更新面板,但面板中的工具具有不同的值。附注:我在我的网站上使用一个依赖于母版页的页面。当我检查任何单选按钮面板不可见!

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:";
    }
}

如果单选按钮被选中,我如何将更新面板设置为可见true ?

听起来好像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"或"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:";
    }
}

因此,如果其中一个被选中,它将显示包含Price Text的框。

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:";
            }
        }