2012-02-07 55 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