Property to set for each RadioButton Control in group - ASP.NET Globalization and Localization

Q.  Which property will you set for each RadioButton Control in the group?
- Published on 28 Jul 15

a. Specify the same GroupName for each RadioButton.
b. Specify the different GroupName for each RadioButton.
c. Specify the same GroupID for each RadioButton.
d. Specify the same ID for each RadioButton.

ANSWER: Specify the same GroupName for each RadioButton.
 

    Discussion

  • Brijesh   -Posted on 19 Oct 15
    Specify the same GroupName for each RadioButton if you want to set for each RadioButton Control in the group.
    Example:
    CS file code.

    protected void Button1_Click(object sender, EventArgs e)
    {
    string str = " ";
    if (rdbAge1.Checked)
    {
    str = rdbAge1.Text;
    }
    else if (rdbAge2.Checked)
    {
    str = rdbAge2.Text;
    }
    if (rdbFemale.Checked)
    {
    str += " " + rdbFemale.Text;
    }
    else if(rdbMale.Checked)
    {
    str += " " + rdbMale.Text;
    }
    Label1.Text = str;
    }

    aspx file code
    < body>
    < form id="form1" runat="server">

    < asp:RadioButton ID="rdbAge1" runat="server" Text="Age<18" GroupName="age" />

    < asp:RadioButton ID="rdbAge2" runat="server" Text="Age>=18"
    GroupName="age" />

    < asp:RadioButton ID="rdbMale" runat="server" GroupName="gender" Text="Male" />

    < asp:RadioButton ID="rdbFemale" runat="server" GroupName="gender"
    Text="Female" />

    < asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    < asp:Label ID="Label1" runat="server" Text="Label">
    < /form>
    < /body>
    In the above example I have taken two group one for gender and one for age.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)