2010-08-06 34 views
2

我想添加一个rsionbuttonlist到我的ascx网页控件..我不断收到一个错误,将radionbuttonlist放入标签中。有没有解决的办法?将radiobuttonlist添加到ascx

" 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="step2.ascx.cs" Inherits="ascx_step2" %> 
<div id="step2" runat="server"> 
    <asp:RadioButtonList id="answers" runat="server">  
    </asp:RadioButtonList> 
<div> 
" 
在后面的代码

ListItem item = new ListItem("a", "a") 
    answers.Items.Add(item); 

错误:

控制 “ctl_00 ...” 类型的单选按钮必须放在一个窗体标记内与RUNAT =服务器

+1

你可以发布你的标记和确切的错误消息你得到? – 2010-08-06 09:11:02

+0

如果错误出现在运行时,请确保您正确地将控件包含在包含页面中。 – brumScouse 2010-08-06 09:59:29

+0

!并且在标记中有适当的结束标记。 – brumScouse 2010-08-06 10:04:57

回答

0
<table> 
    <tr> 
     <td> 
      Drag and drop from the tool box, in UI mode 
     <td> 
     </tr> 

</table> 
+0

您在这里假设OP正在使用表格进行布局,这是不推荐的。 – 2010-08-06 09:14:22

0

确保将控件正确添加到包含页面(包含表单元素),并且单选按钮列表中正确声明:

<asp:RadioButtonList ID="rblSomeRadioButtonList" runat="server"> 
    <asp:ListItem Text="Something" Value="True"/> 
</asp:RadioButtonList> 
+0

其内的一个用户控件,所以我不能添加表单标签 – maggie 2010-08-06 09:42:11

0

下面是检查的几件事情:

  • 也许这只是一个错字,但你的例子.ASCX标记具有不属于中一开头和结尾报价一个真正的.ascx文件。
  • 确保您的用户控件放置在表单标签内的页面上。

MyPage.aspx:

<html> 
    <body> 
    <form id="form1" runat="server"> 
     <myprefix:MyUserControl ID="mycontrol" runat="server" /> 
    </form> 
    </body> 
</html> 
  • 如果要动态地添加用户控件在代码中隐藏的页面上,确保将其添加的东西,已经是正确的表格内标签。
相关问题