2012-10-23 62 views
0

状态显示错误我有以下输入标签asp.net表里面如果单选按钮ID

<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条件,单选按钮的显示错误。

error when if condition included

这是为什么发生的任何想法?

+6

你是否缺少'runat =“server”'? –

+1

绝对.. Runat服务器丢失.. – pordi

+0

我添加runat =“服务器”,但仍然有问题:( – Mohsinjan110

回答

1

你应该使用asp:RadioButton来访问后面的代码。

所以基本上用“asp:RadioButton”替换所有的“输入”标签并删除类型等非感性属性。

的asp:单选按钮使用例子

2

尝试使用Asp.net控制:

<asp:RadioButton runat="server" ... /> 
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