Export (0) Print
Expand All

HtmlInputRadioButton.Checked Property

Gets or sets a value indicating whether the HtmlInputRadioButton control is selected.

[Visual Basic]
Public Property Checked As Boolean
[C#]
public bool Checked {get; set;}
[C++]
public: __property bool get_Checked();
public: __property void set_Checked(bool);
[JScript]
public function get Checked() : Boolean;
public function set Checked(Boolean);

Property Value

true if the HtmlInputRadioButton control is selected; otherwise, false.

Remarks

Use the Checked property to determine whether the HtmlInputRadioButton control is selected. If you have a group of HtmlInputRadioButton controls, you must iterate through the controls and test the Checked property of each control individually. You can also use this property to programmatically specify whether the control is selected.

You can group HtmlInputRadioButton controls together by specifying a common value for the Name property of each radio button control you want to include in the group.

Note   When you group HtmlInputRadioButton controls, only one radio button in the group can be selected at a time. The Checked property of the selected control is set to true, while the same property is set to false for all other radio buttons in the group.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Checked property to determine which radio button in the group is selected.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs)
        
        If Radio1.Checked = True Then
            Span1.InnerHtml = "Option 1 is selected"
        Else
            If Radio2.Checked = True Then
                Span1.InnerHtml = "Option 2 is selected"
            Else
                If Radio3.Checked = True Then
                    Span1.InnerHtml = "Option 3 is selected"
                End If
            End If
        End If
    End Sub 'Button1_Click

   </script>

</head>
<body>

   <form runat=server>

      <h3>HtmlInputRadioButton Sample</h3>

      <input type="radio" 
             id="Radio1" 
             name="Mode" 
             runat="server"/>

      Option 1<br>

      <input type="radio" 
             id="Radio2" 
             name="Mode" 
             runat="server"/>
      
      Option 2<br>

      <input type="radio" 
             id="Radio3" 
             name="Mode" 
             runat="server"/>

      Option 3

      <p>
      <span id="Span1" runat="server" />

      <p>
      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server">

   </form>

</body>
</html>
   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script language="C#" runat="server">

      void Button1_Click(object sender, EventArgs e) 
      {

         if (Radio1.Checked == true)
            Span1.InnerHtml = "Option 1 is selected";
         else if (Radio2.Checked == true)
            Span1.InnerHtml = "Option 2 is selected";
         else if (Radio3.Checked == true)
            Span1.InnerHtml = "Option 3 is selected";
      }

   </script>

</head>
<body>

   <form runat=server>

      <h3>HtmlInputRadioButton Sample</h3>

      <input type="radio" 
             id="Radio1" 
             name="Mode" 
             runat="server"/>

      Option 1<br>

      <input type="radio" 
             id="Radio2" 
             name="Mode" 
             runat="server"/>
      
      Option 2<br>

      <input type="radio" 
             id="Radio3" 
             name="Mode" 
             runat="server"/>

      Option 3

      <p>
      <span id="Span1" runat="server" />

      <p>
      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server">

   </form>

</body>
</html>
   

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JSCRIPT" runat="server">

    function Button1_Click(sender : Object, e : EventArgs){
        
        if(Radio1.Checked)
            Span1.InnerHtml = "Option 1 is selected"
        else if(Radio2.Checked)
            Span1.InnerHtml = "Option 2 is selected"
        else if(Radio3.Checked)
            Span1.InnerHtml = "Option 3 is selected"
    }

   </script>

</head>
<body>

   <form runat=server>

      <h3>HtmlInputRadioButton Sample</h3>

      <input type="radio" 
             id="Radio1" 
             name="Mode" 
             runat="server"/>

      Option 1<br>

      <input type="radio" 
             id="Radio2" 
             name="Mode" 
             runat="server"/>
      
      Option 2<br>

      <input type="radio" 
             id="Radio3" 
             name="Mode" 
             runat="server"/>

      Option 3

      <p>
      <span id="Span1" runat="server" />

      <p>
      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server">

   </form>

</body>
</html>
   

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlInputRadioButton Class | HtmlInputRadioButton Members | System.Web.UI.HtmlControls Namespace | Name

Show:
© 2014 Microsoft