0

我在 asp.net 的表中有以下输入标签

<td class="style18">
    <asp:CheckBox ID="chkContentTone" onclick="enableGroupBoxTone()" 
                    runat="server" Text="Content Tone" CssClass="ChkBoxStyle"/>&nbsp;
</td>
<td class="styleCntTon">
    <input type="radio" id="rdBtnPositive" name="q2" title="Posotivetitle" value="positive"/>
    <label for="rdbtnPositive" class="RadioGroup">Positive</label>
    <input type="radio" id="rdBtnNegative" name="q2" title="Negativetitle" value="negative"/>
    <label for="rdBtnNegative" class="RadioGroup">Negative</label>
    <input type="radio" id="rdBtnNeutral" name="q2" title="Neutraltitle" value="neutral"/> 
    <label for="rdBtnNeutral" class="RadioGroup">Neutral</label>
</td> 

但是当我输入if条件时,单选按钮会显示错误。

包含条件时出错

任何想法为什么会发生这种情况?

4

3 回答 3

2

尝试使用 Asp.net 控件:

<asp:RadioButton runat="server" ... />
于 2012-10-23T14:39:28.937 回答
2

您发布的标记不包括服务器端控件,因此无法通过服务器端代码访问这些控件。

看着你想要的似乎你需要一个asp:RadioButton

添加后,asp:radiobutton您可以在服务器端代码中访问这些控件。

改变这个:

<input type="radio" id="rdBtnPositive" name="q2" title="Posotivetitle" value="positive"/><label for="rdbtnPositive" class="RadioGroup">Positive</label>

对此:

<asp:RadioButton id="rdBtnPositive" Label="Positive" runat="server" />

然后你可以这样做:

if(rdBtnPositive.Checked)
 {
  //code it...
 }

您需要对所有三个单选按钮执行此操作,每个单选按钮都应该有一个唯一的 id 并且是服务器端控件,即asp:RadioButton.

于 2012-10-23T14:39:54.950 回答
1

您应该使用 asp:RadioButton 才能在后面的代码中访问。

所以基本上用“asp:RadioButton”替换所有“输入”标签并删除像Type这样的不明智的属性。

asp:RadioButton 使用示例

于 2012-10-23T14:37:45.590 回答