Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I have to radio button... rbtn1.text="yes" and rbtn2="no"
on page load panel should invisible..
if text = "yes" then panel should visible..
if text="no" then panel should invisible...
Posted
Comments
m@dhu 19-Sep-11 1:41am    
Instead using radiobuttonlist with two list items would be a better option.

Hi,

Try this-

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("input[name*=group1]").click(function () {
            if ($(this).val().indexOf("Yes")>=0)
                $("div[id*=Panel1]").show();
            else
                $("div[id*=Panel1]").hide();

        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:RadioButton ID="Yes" runat="server" Text="Yes" GroupName="group1" />
    <asp:RadioButton ID="No" runat="server" Text="No" GroupName="group1" />
    <asp:Panel ID="Panel1" runat="server" style="background-color:Gray; height:300px;display:none">
    </asp:Panel>
    </form>
</body>
</html>
 
Share this answer
 
Comments
ujju.1 4-Jun-12 3:09am    
thank you mate...this is exactly what I needed.
Member 10290905 20-Nov-13 8:33am    
i want close panel data when we click on raio buttion how to visible data plese help me
You can do it on RadioButton CheckChanged event. But make sure, both of your RadioButton are under same Group !
 
Share this answer
 
Comments
Member 10290905 20-Nov-13 8:36am    
i have three raido button when we click on one then two button panel shuld be visible,
again i click on next button then click button panel shuld be visible other two shuold be non visible
pls help me
on form load set visible property of panel = false
and set visible =true in checkedChanged event of radio button.
 
Share this answer
 
Comments
Sant Osha 19-Sep-11 1:14am    
i know .. i did that..
but when you checked 'no' after checking 'yes' its not working....
yogesh89 19-Sep-11 1:17am    
both radiobutton should be in one group or in panel.
it will work.....
Sant Osha 19-Sep-11 1:19am    
there are in one group.
following is code:-
protected void rbtYes_CheckedChanged(object sender, EventArgs e)
{
if (rbtYes.Checked)
{
panel.Visible = true;
}

}
protected void rbtNo_CheckedChanged(object sender, EventArgs e)
{
if (rbtNo.Checked)
{
panel.Visible = false;
}
}
yogesh89 19-Sep-11 1:33am    
the code should be like this......

protected void rbtYes_CheckedChanged(object sender, EventArgs e) { if (rbtYes.Checked==true) { panel.Visible = true; } } protected void rbtNo_CheckedChanged(object sender, EventArgs e) { if (rbtNo.Checked==true) { panel.Visible = false; } }
Sant Osha 19-Sep-11 1:39am    
i did use code also. but its not working

but when you checked 'no' after checking 'yes' its not working
First of all, a pair of radio buttons with two values "Yes" and "No" hardly have a right to exist. Instead, you should use one check box like "Show the… panel".

It will look like
C#
myButton.CheckedChanged += (sender, eventArgs) => { MyPanel.Visible = ((CheckBox)sender).Checked; }


—SA
 
Share this answer
 
v2
if (rbtn1.Text == "Yes")
{
Panel1.Visible = true;
Panel2.Visible = false;
}
else if (rbtn2.Text == "No")
{
Panel1.Visible = false;
Panel2.Visible = true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900