Nitin Sharma

Nitin Sharma

  • NA
  • 154
  • 59.3k

how radiobutton checkchanged event work in asp.net webform

Mar 18 2014 9:08 AM
can anybody tell me that how radiobutton checkchanged event work in asp.net webform.
my coding is working in windows form but same coding is not working in webform. i m pasting my code 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 184px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <table class="style1">
            <tr>
                <td class="style2">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="a" 
                        oncheckedchanged="RadioButton1_CheckedChanged" />
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Button" Visible="False" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="a" 
                        oncheckedchanged="RadioButton2_CheckedChanged" />
                </td>
                <td>
                    <asp:Button ID="Button2" runat="server" Text="Button" Visible="False" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:RadioButton ID="RadioButton3" runat="server" GroupName="a" 
                        oncheckedchanged="RadioButton3_CheckedChanged" />
                </td>
                <td>
                    <asp:Button ID="Button3" runat="server" Text="Button" Visible="False" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
    
    </div>
    </form>
</body>
</html>

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        if (RadioButton1.Checked == true)
        {
            Button1.Visible = true;
            Button2.Visible = false;
            Button3.Visible = false;
            RadioButton2.Checked = false;
            RadioButton3.Checked = false;
        }
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        if (RadioButton2.Checked == true)
        {
            Button1.Visible = false;
            Button2.Visible = true;
            Button3.Visible = false;
            RadioButton1.Checked = false;
            RadioButton3.Checked = false;
        }
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        if (RadioButton3.Checked == true)
        {
            Button1.Visible = false;
            Button2.Visible = false;
            Button3.Visible = true;
            RadioButton1.Checked = false;
            RadioButton2.Checked = false;
        }
    }
}

Answers (6)