rai nalasa
rai nalasa

Reputation: 859

RadioButton can be clicked at the same time

RadioButton supposed to be clicked one at a time right? how come I could click it both?

enter image description here

here is my mark up:

<fieldset style="width: 158px; margin-top: 5%;float:left;margin-left:3%;">
    <legend>Add/Update Products</legend>
    <label>
        Add
       <asp:RadioButton ID="RadioButton2" runat="server" />&nbsp;Update<asp:RadioButton ID="RadioButton1" runat="server" />
    </label>
     <br />
    <label>
        Category:
        <br />
        <asp:TextBox align="middle" ID="txtCategory" runat="server" CssClass="textbox1"></asp:TextBox></label>
    <br />
    <label>
        Type:
        <br />
        <asp:TextBox align="middle" ID="txtType" runat="server" CssClass="textbox1"></asp:TextBox></label>
    <br />
    <label>
        Image:
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" /></label>
    <br />
    <label>
        <asp:Label ID="lblFileStatus" runat="server" Text=""></asp:Label>
        <asp:Label ID="lblFile" runat="server" Text=""></asp:Label>
    </label>
    <label>
        <asp:Button ID="btnAdd" runat="server" Text="Submit" CssClass="btnAdd" Height="36px" Width="84px" OnClick="btnAdd_Click" />
        &nbsp;
   <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btnCancel" Height="36px" Width="84px" />
    </label>
</fieldset>

I need to only choose one. But when I tried to click again the same button twice the mark won't disappear.

Upvotes: 0

Views: 75

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39946

When only one selection is possible from a list of available options you need to set the GroupName for both RadioButtons. When this property is set, only one RadioButton in the specified group can be selected at a time:

<asp:RadioButton ID="RadioButton2" runat="server" GroupName="gr1"/>
&nbsp;Update
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="gr1"/>

Upvotes: 1

Related Questions