Parag’s Den

Dedicated to my adored friends…..

RadioButton Web Server Control

Posted by paragdongre on November 6, 2007

RadioButton Web Server Control is perfect for questions who has only one answer. The RadioButton web server control is almost the same as the CheckBox web server control. The only thing that is different here is that, you have to use a property called GroupName to the collection of your radio buttons. Other than that it is the same as the Checkbox control.

  1. How to assign a text to Radio Button control?
  2. How to know which RadioButton has been selected by the user?
RadioButton – How to assign a text how to know radio button have been selected?

To assign a text, we need to use the text property and to know whether the radio button have been selected, we need to use the selected property, which returns either true or false.

<title>RadioButton Web Server Control – by Das </title><script language=vb runat=server>

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
     rd1.Text = “Doctor”
     rd2.Text = “Software Engineer”
     rd3.Text = “Lawyer”
     rd4.Text = “Business Man”
     rd5.Text = “Other”
End Sub

Public Sub btnSubmit_OnClick(ByVal sender As Object, ByVal e As EventArgs)
     If rd1.Checked Then
          lblResult.Text = “So, you are a ” & rd1.Text & ” (Any surgeries so far?)”
     ElseIf rd2.Checked Then
          lblResult.Text = “So, you are a ” & rd2.Text & ” (So you work with Computers, right)”
     ElseIf rd3.Checked Then
          lblResult.Text = “So, you are a ” & rd3.Text & ” (How may cases have you attended so far?)”
     ElseIf rd4.Checked Then
          lblResult.Text = “So, you are a ” & rd4.Text & ” (Self employeed, huh)”
     ElseIf rd5.Checked Then
          lblResult.Text = “So, you are a ” & rd5.Text & ” (What else you are, just curious?)”
          lblResult.Text = “OOPS! you selected nothing! Try again.”
     End If
End Sub


<form id=”Form1″ method=”post” runat=”server”>

     <h3>ASP .NET Tutorial: Working with Radio Button Control.

     <asp:Label ID=”lblMsg” Text=”What is your profession?” Runat=server />
     <asp:RadioButton ID=”rd1″ GroupName=profession Runat=server />
     <asp:RadioButton ID=”rd2″ GroupName=profession Runat=server />
     <asp:RadioButton ID=”rd3″ GroupName=profession Runat=server />
     <asp:RadioButton ID=”rd4″ GroupName=profession Runat=server />
     <asp:RadioButton ID=”rd5″ GroupName=profession Runat=server />
     <asp:Button ID=”btnSubmit” Text=”Submit” OnClick=”btnSubmit_OnClick” Runat=server />
     <asp:Label ID=”lblResult” ForeColor=”#ff0000″ Font-Bold=”True” Runat=server />




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: