可以同时单击RadioButton

时间:2016-06-05 13:14:37

标签: c# asp.net radio-button

应该一次点击一次

RadioButton吗? 为什么我可以点击它?

enter image description here

这是我的标记:

<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>

我只需要选择一个。但是当我试图再次点击同一个按钮两次时 这个标志不会消失。

1 个答案:

答案 0 :(得分:1)

当可用选项列表中只有一个选项时,您需要为RadioButtons设置GroupName。设置此属性后,一次只能选择指定组中的一个RadioButton

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