Get selected RadioButton : RadioButton « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="test" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        What is your favorite ice cream flavor?
        <br />
        <br />
        <asp:RadioButton ID="A" GroupName="flavors" runat="server" Text="A" /><br />
        <br />
        <asp:RadioButton ID="B" GroupName="flavors" runat="server" Text="B" /><br />
        <br />
        <asp:RadioButton ID="C" GroupName="flavors" runat="server" Text="C" /><br />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Click Me" /><br />
        <br />
        <asp:Label ID="results" runat="server"></asp:Label></div>
    </form>
</body>
</html>


File: Default.aspx.vb


Partial Class test
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If A.Checked Then
            results.Text = "A"
        ElseIf B.Checked Then
            results.Text = "B"
        ElseIf C.Checked Then
            results.Text = "C"
        End If

    End Sub
End Class








3.13.RadioButton
3.13.1.Important properties, methods and events for RadioButton
3.13.2.Use RadioButton to set font size
3.13.3.Use AutoPostBack property to detect which RadioButton control is selected.
3.13.4.Get selected RadioButton
3.13.5.asp:RadioButton changed event (C#)