2012-02-07 104 views
0

我有兩個radio buttons和兩個panels在我的網頁上,我想show面板1當單選按鈕1選中更改並隱藏面板2和類似的面板2需要顯示當單選按鈕2選中更改並隱藏PANEL1。使用單選按鈕顯示和隱藏面板

這是我怎麼沒有成功完成

這裏是我的單選按鈕:

<asp:RadioButton ID="RadioButton1" runat="server" Text="Text" ForeColor="White" GroupName="selection" OnCheckedChanged="RadioButton1_CheckedChanged"/> 

<asp:RadioButton ID="RadioButton2" runat="server" Text="Image" ForeColor="White" GroupName="selection" OnCheckedChanged="RadioButton2_CheckedChanged"/> 

這RadioButton1_CheckedChanged:

If RadioButton1.Checked = True Then 
      RadioButton2.Checked = False 
      Panel1.Visible = True 
      Panel2.Visible = False 
End If 

這RadioButton2_CheckedChanged:

If RadioButton2.Checked = True Then 
      RadioButton1.Checked = False 
      Panel1.Visible = False 
      Panel2.Visible = True 
End If 
+0

需要將Autopostback設置爲true纔能有效工作。 – JonH 2012-02-07 16:36:32

回答

2

您需要爲單選按鈕設置autopostback爲true。 AutoPostback="True"包括在你的單選按鈕標籤,你應該很好去。一個簡單的代碼調試會告訴你,這兩個事件都不是用你當前的代碼調用的。

+0

@ John-感謝您的回覆,並且我可以使用面板更新面板並將單選按鈕回發屬性設置爲true,因爲我不想回發。 – coder 2012-02-07 16:37:50

+0

@DotNetter - 如果你不想回發,爲什麼你不在服務器端處理這個問題?使用簡單的JavaScript到'getElementById'或'getElementByName'並設置可見性屬性。此外,在服務器端代碼中執行此操作並不基於您現有的代碼(您沒有處理任何數據或執行任何數據密集型工作),因此沒有特殊/特定的用途。 – JonH 2012-02-07 16:39:09

+1

Yeh gud point.I will do that。 – coder 2012-02-07 16:40:30