// Default3.aspx //
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">RadioButton in ASP.NET 4 , C#</h2>
<strong>My age between:
</strong>
<br />
<br />
<asp:RadioButton ID="RadioButton1" Text="10-15 years" GroupName="Age"
runat="server" OnCheckedChanged="RadioButtonAge_CheckedChanged" AutoPostBack="true"/>
<br />
<asp:RadioButton ID="RadioButton2" Text="15-20 years" GroupName="Age"
runat="server" OnCheckedChanged="RadioButtonAge_CheckedChanged" AutoPostBack="true"/>
<br />
<asp:RadioButton ID="RadioButton3" Text="20-25 years" GroupName="Age"
runat="server" OnCheckedChanged="RadioButtonAge_CheckedChanged" AutoPostBack="true"/>
<br />
<asp:RadioButton ID="RadioButton4" Text="25-30 years" GroupName="Age"
runat="server" OnCheckedChanged="RadioButtonAge_CheckedChanged" AutoPostBack="true"/>
<br />
<br />
<asp:Label ID="Label1" runat="server" BackColor="#FFFF99" Font-Bold="True"
ForeColor="#000099" />
</div>
</form>
</body>
</html>
// Default3.aspx.cs //
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButtonAge_CheckedChanged(object sender, System.EventArgs e)
{
if (RadioButton1.Checked == true)
{
Label1.Text = "My age between 10-15 years";
}
else if (RadioButton2.Checked == true)
{
Label1.Text = "My age between 15-20 years";
}
else if (RadioButton3.Checked == true)
{
Label1.Text = "My age between 20-25 years";
}
else if (RadioButton4.Checked == true)
{
Label1.Text = "My age between 25-30 years";
}
}
}
OUTPUT
No comments:
Post a Comment