[英]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.