ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
Professional ASP.NET Web Services
Professional ASP.NET Web Services

Find Prices
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software

RadioButton Web Server Control

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.

<HTML>
<HEAD>
<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?)"
     Else
          lblResult.Text = "OOPS! you selected nothing! Try again."
     End If
End Sub

</script>
</head>
<body>

<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 />

</form>

</body>
</HTML>

Test this Script

Conclusion

You can also add attributes and retrieve attributes for this control. To know more about adding and retrieving attributes, please read my article on Checkbox web server control.

Send your comments to das@aspalliance.com         Back to Tutorial

 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 11/21/2009 3:46:57 PM