尝试呈现转发器控件时表单标记错误

时间:2012-08-16 17:47:09

标签: c# asp.net

在尝试渲染我的转发器的html时,我得到表单标记错误(...必须放在带有runat = server的表单标记内。在System.Web.UI.Page.VerifyRenderingInServerForm ...中)。

对渲染的调用:

System.Text.StringBuilder stringbuilder = new System.Text.StringBuilder();
StringWriter stringwriter = new StringWriter(stringbuilder);
HtmlTextWriter htmltextwriter = new HtmlTextWriter(stringwriter);
rptEvaluation.RenderControl(htmltextwriter);//repeater control

content += stringbuilder.ToString(); //content is a string variable. 

在没有渲染组件的情况下,页面和代码可以正常工作。

有什么想法吗?

谢谢,亚当。这是我的中继器

<asp:Repeater ID="rptEvaluation" runat="server" OnItemDataBound="rptEvaluation_OnItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>Category Name</th>
</tr>
</HeaderTemplate>

<AlternatingItemTemplate>
<asp:HiddenField ID="hfCatID" runat="server" Value='<%#Eval("CategoryId") %>' />
<tr style="background-color:#eee;">
<td><%# DataBinder.Eval(Container.DataItem, "Category") %></td>
</tr>
<tr>
<td>
<asp:Repeater ID="rptCategoryQuestions" runat="server">
                    <HeaderTemplate>
                        <table>
                            <tr>
                            <th>Question ID</th>
                            <th>Question</th>
                            <th>Student score</th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                    <asp:HiddenField ID="hfQuestID" runat="server" Value='<%#Eval("QuestionID") %>' />
                            <tr>
                                <td><%# DataBinder.Eval(Container.DataItem, "QuestionID") %></td>
                                <td><%# DataBinder.Eval(Container.DataItem, "Question") %></td>
                                <td>
                                    <asp:RadioButtonList ID="rblScore" runat="server">
                                        <asp:ListItem Text="Approaching" Value="1"></asp:ListItem>    
                                        <asp:ListItem Selected="True" Text="Meets" Value="2"></asp:ListItem>    
                                        <asp:ListItem Text="Exceeds" Value="3"></asp:ListItem>    
                                    </asp:RadioButtonList>
                               </td>
                            </tr>
                        </ItemTemplate>
                    <AlternatingItemTemplate>
                    <asp:HiddenField ID="hfQuestID" runat="server" Value='<%#Eval("QuestionID") %>' />
                            <tr>
                                <td><%# DataBinder.Eval(Container.DataItem, "QuestionID") %></td>
                                <td><%# DataBinder.Eval(Container.DataItem, "Question") %></td>
                                <td>
                                    <asp:RadioButtonList ID="rblScore" runat="server">
                                        <asp:ListItem Text="Approaching" Value="1"></asp:ListItem>    
                                        <asp:ListItem Selected="True" Text="Meets" Value="2"></asp:ListItem>    
                                        <asp:ListItem Text="Exceeds" Value="3"></asp:ListItem>    
                                    </asp:RadioButtonList>
                               </td>
                            </tr>
                     </AlternatingItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
            </td>
        </tr>
</AlternatingItemTemplate>

<ItemTemplate>
    <asp:HiddenField ID="hfCatID" runat="server" Value='<%#Eval("CategoryId") %>' />
        <tr style="background-color:#666;">
            <td><%# DataBinder.Eval(Container.DataItem, "Category") %></td>
        </tr>
        <tr>
            <td>
                <asp:Repeater ID="rptCategoryQuestions" runat="server">
                    <HeaderTemplate>
                        <table>
                            <tr>
                            <th>Question ID</th>
                            <th>Question</th>
                            <th>Student Score</th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                    <asp:HiddenField ID="hfQuestID" runat="server" Value='<%#Eval("QuestionID") %>' />
                            <tr>
                                <td><%# DataBinder.Eval(Container.DataItem, "QuestionID") %></td>
                                <td><%# DataBinder.Eval(Container.DataItem, "Question") %></td>
                                <td>
                                    <asp:RadioButtonList ID="rblScore" runat="server">
                                        <asp:ListItem Text="Approaching" Value="1"></asp:ListItem>    
                                        <asp:ListItem Selected="True" Text="Meets" Value="2"></asp:ListItem>    
                                        <asp:ListItem Text="Exceeds" Value="3"></asp:ListItem>    
                                    </asp:RadioButtonList>
                               </td>
                            </tr>
                        </ItemTemplate>
                    <AlternatingItemTemplate>
                    <asp:HiddenField ID="hfQuestID" runat="server" Value='<%#Eval("QuestionID") %>' />
                            <tr>
                                <td><%# DataBinder.Eval(Container.DataItem, "QuestionID") %></td>
                                <td><%# DataBinder.Eval(Container.DataItem, "Question") %></td>
                                <td>
                                    <asp:RadioButtonList ID="rblScore" runat="server">
                                        <asp:ListItem Text="Approaching" Value="1"></asp:ListItem>    
                                        <asp:ListItem Selected="True" Text="Meets" Value="2"></asp:ListItem>    
                                        <asp:ListItem Text="Exceeds" Value="3"></asp:ListItem>    
                                    </asp:RadioButtonList>
                               </td>
                            </tr>
                     </AlternatingItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
            </td>
        </tr>
    </ItemTemplate>
<FooterTemplate>
     </table>
</FooterTemplate>

0 个答案:

没有答案