[英]How can I set visible true for update Panel if Radio Button Checked?
我有2个单选按钮,它们都应该在页面中显示一个更新面板,但是面板中工具的值不同。 PS:我使用的页面取决于我网站上的母版页。 当我检查任何一个单选按钮时,面板不可见!
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:";
}
}
听起来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:";
}
}
因此,如果选择了其中一个,它将显示其中带有价格文本的框。 这可以做您想要的更好的方法。
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:";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.