Unique selection of Radiobutton

Asked

Viewed 33 times

0

Hello, I would like to ask for help on the unique selection of a Radiobutton, I inserted two on my page and I wish only 1 could be selected if the other was automatically unchecked the other...

<div class="col-xs-3 col-lg-2 radiobutton">
            <asp:RadioButton ID="RadioBtnPar" runat="server" Text="Par" OnCheckedChanged="RadioBtnPar_CheckedChanged"/>
            <asp:RadioButton ID="RadioBtnImpar" runat="server" Text="Ímpar" OnCheckedChanged="RadioBtnImpar_CheckedChanged"/>
        </div>

Assim que fica, mas quero o que comentei acima

 protected void RadioBtnPar_CheckedChanged(object sender, EventArgs e)
{
    RadioBtnImpar.AutoPostBack = true;
    RadioBtnImpar.Checked = false;
}

protected void RadioBtnImpar_CheckedChanged(object sender, EventArgs e)
{
    RadioBtnPar.Checked = false;
}

Here are the checkedchanged event commands, thanks in advance

1 answer

1


To choose from several RadioButton, they need to have the same name in html (for example name="parimpar")

How are you using the control of asp-net, use the property GroupName, for example GroupName="ParImpar" in all radiobutton, which will look like this in html:

<input type="radio" ID="RadioBtnPar" name="ParImpar" />Par  
<input type="radio" ID="RadioBtnImpar" name="ParImpar" />Ímpar  

  • Thank you very much, I had used name="", but I didn’t know it was only HTML, now it’s working, even Rigadão!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.