将radiobuttonlist添加到ascx

时间:2010-08-06 09:06:38

标签: c#

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

"
<%@ 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);

错误:

类型radiobutton的“ctl_00 ...”必须放在带有runat = server的表单标签内

3 个答案:

答案 0 :(得分:0)

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

</table>

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

以下是一些要检查的事项:

  • 也许这只是一个错字,但您的示例.ascx标记有一个前导和尾随引用,不属于真正的.ascx文件。
  • 确保您的用户控件位于表单标记内的页面上。

MyPage.aspx:

<html>
  <body>
    <form id="form1" runat="server">
      <myprefix:MyUserControl ID="mycontrol" runat="server" />
    </form>
  </body>
</html>
  • 如果您在代码隐藏中动态地将用户控件添加到页面,请确保将其添加到已在正确的表单标记内的内容。
相关问题