Search Your Dot Net Topic

Sunday, 25 April 2021

Radio Button Asp.Net WebForm | radio button in asp.net c# for gender | R...




CODE: radio-button-sample.aspx   

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="radio-button-sample.aspx.cs" Inherits="radio_button_sample" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButton ID="rbtnMale" runat="server" Text="Male" GroupName="gender"  />
        <asp:RadioButton ID="rbtnFemale" runat="server" Text="Female" GroupName="gender"  />
    </div>
        <br />
        <br />
        <asp:Button ID="btnSubmit" Text="Submit" runat="server"  OnClick="btnSubmit_Click"/>
        <br />
        <br />
        <asp:Label ID="lblMsg" runat="server"></asp:Label>
    </form>
</body>
</html>



CODE:  radio-button-sample.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 radio_button_sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (rbtnMale.Checked == true)
        {
            lblMsg.Text = "You selected  gender " + rbtnMale.Text;
        }
        else
        {
            lblMsg.Text = "You selected  gender " + rbtnFemale.Text;
        }
    }
}



No comments:

Post a Comment