类型“TextBox”的控件“Repeater1_ctl01_txKjfsBz”必须放在具有 runat=server 的窗体标记内
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息: System.Web.HttpException: 类型“TextBox”的控件“Repeater1_ctl01_txKjfsBz”必须放在具有 runat=server 的窗体标记内。
源错误:
行 105: protected void BtnExcel_Click(object sender, EventArgs e)
行 106: {
行 107: PageHelper.ControlExportExcel(System.Web.HttpContext.Current, this.DetailPanel);
行 108: }
行 109:
说明:TextBox在form中,并也有runat="server"
<form>
<table></table>
<asp:Panel>
<table></table>
<asp:Repeater1>TextBox在此处报错</asp:Repeater1>
<asp:Repeater2></asp:Repeater2>
<asp:Repeater3></asp:Repeater3>
<table></table>
</asp:Panel>
</form>
请各位大侠指点下!急 --------------------编程问答-------------------- System.Web.HttpException: 类型“TextBox”的控件“Repeater1_ctl01_txKjfsBz”必须放在具有 runat=server 的窗体标记内。
<asp:Repeater1 runat=server>
试下
--------------------编程问答-------------------- 源代码如下:
<body>
<form id="form1" runat="server">
<table id="ConditionTable" style="border-bottom-style:none;background:#ffffff" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td style="border-bottom-style:none;border-right-style:none;background:#ffffff" >
<asp:Label ID="LabGcmc" runat="server" Text=""></asp:Label>
<asp:Label ID="LabYdzf" runat="server" Text="" style="display:none"></asp:Label>
<asp:Label ID="LabKjzf" runat="server" Text="" style="display:none"></asp:Label>
<asp:Label ID="LabSdzf" runat="server" Text="" style="display:none"></asp:Label>
<%--<asp:Label ID="LabFindJcpfb" runat="server" Text="" style="display:none"></asp:Label>--%>
</td>
</tr>
<tr>
<td align="right" style="border-bottom-style:none;border-left-style:none;background:#ffffff">
检查评分表: <asp:TextBox ID="FindJcpfb" runat="server" Width="100px" MaxLength="50"></asp:TextBox>
<%--年份:<asp:DropDownList ID="Findnf" runat="server">
</asp:DropDownList>
月份:<asp:DropDownList ID="Findyf" runat="server">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>--%>
<asp:Button ID="BtnSearch" runat="server" Text="查询" onclick="BtnSearch_Click" />
<asp:Button ID="BtnExcel" runat="server" Text="数据导出Excel" onclick="BtnExcel_Click" />
</td>
</tr>
</table>
<asp:Panel ID="DetailPanel" runat="server" Width="100%">
<table width="1000" runat="server" border="1" align="center" style="border-style: none">
<tr><td align="center" style="border-style: none">
<asp:Label ID="labJcpfbName" runat="server" Text=""></asp:Label></td>
</tr>
<tr><td align="right" style="border-style: none">
<asp:Label ID="LabJcpfbID" runat="server" Text=""></asp:Label></td>
</tr>
</table>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="processItemCommand">
<HeaderTemplate >
<table width="1000" border="1" align="center">
<tr>
<td align="center" width="5%">序号</td>
<td colspan="2" align="center" width="20%">检查项目</td>
<td align="center" width="40%">扣分标准</td>
<td align="center" width="10%">应得分数</td>
<td align="center" width="10%">扣减分数</td>
<td align="center" width="10%">实得分数</td>
<td align="center" width="5%">评分</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%#Container.ItemIndex+1%></td>
<td align="center" width="8%" rowspan="1">保证项目</td>
<td align="center"><%#Eval("BJcxm") %></td>
<td><%#Eval("BKfbz")%></td>
<td align="center"><%#Eval("BYdfs")%></td>
<td align="center">
<asp:TextBox ID="txKjfsBz" runat="server" align="center" style="text-align:center" Width="40%" MaxLength="15" require="false" Visible = "true"
dataType="Double" msg="Input must be number" Text='<%#Eval("BKjfs") %>'></asp:TextBox>
</td>
<td align="center"><%#Eval("BSdfs")%></td>
<td align="center">
<asp:Button ID="btnBzxm" runat="server" Text="评分" CommandName="pfBzxm" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td></td>
<td colspan="2" align="center">小计</td>
<td></td>
<td align="center"><%#TempHashTable1["BYs"]%></td>
<td align="center"><%#TempHashTable1["BKs"]%></td>
<td align="center"><%#TempHashTable1["BSs"]%></td>
<td></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="Repeater2" runat="server" OnItemCommand="processItemCommand">
<HeaderTemplate>
<table width="1000" border="1" align="center" >
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center" width="5%" style="border-top-style: none;"><%#Repeater1.Items.Count + Container.ItemIndex + 1%></td>
<td align="center" width="8%" rowspan="1" style="border-top-style: none;">一般项目</td>
<td align="center" style="border-top-style: none;"><%#Eval("YJcxm") %></td>
<td width="40%" style="border-top-style: none;"><%#Eval("YKfbz") %></td>
<td align="center" width="10%" style="border-top-style: none;"><%#Eval("YYdfs")%></td>
<td align="center" width="10%" style="border-top-style: none;">
<asp:TextBox ID="txKjfsYb" runat="server" align="center" style="text-align:center" Width="40%" MaxLength="15" require="false" Visible = "true"
dataType="Double" msg="Input must be number" Text='<%#Eval("YKjfs") %>'></asp:TextBox>
</td>
<td align="center" width="10%" style="border-top-style: none;"><%#Eval("YSdfs")%></td>
<td align="center" width="5%" style="border-top-style: none;">
<asp:Button ID="btnYbxm" runat="server" Text="评分" CommandName="pfYbxm" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td align="center" width="5%" style="border-top-style: none;"></td>
<td colspan="2" align="center" width="20%" style=" border-top-style: none;">小计</td>
<td align="center" width="40%"style="border-top-style: none;"></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable2["YYs"]%></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable2["YKs"]%></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable2["YSs"]%></td>
<td style="border-top-style: none;"></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="Repeater3" runat="server" OnItemCommand="processItemCommand">
<HeaderTemplate>
<table width="1000" border="1" align="center">
</HeaderTemplate>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<tr>
<td align="center" width="5%" style="border-top-style: none;"></td>
<td colspan="2" align="center" width="20%" style=" border-top-style: none;">合计</td>
<td align="center" width="40%"style="border-top-style: none;"></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable["Ys"]%></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable["Ks"]%></td>
<td align="center" width="10%"style="border-top-style: none;"><%#TempHashTable["Ss"]%></td>
<td align="center" width="5%" style="border-top-style: none;">
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<table id="Table1" width="1000" border="1" align="center" style="border-top-style: none; background: #e7e6ff" OnItemCommand="processItemCommand" OnItemCreated="processItemCreate">
<tr>
<td align="right" style="border-top-style: none; background: #e7e6ff">
<img ID="backto" align="absmiddle" alt="返回" onclick="Backto()"
src="../images/back.gif" style="cursor:pointer" />
</td>
</tr>
</table>
</asp:Panel>
</form>
</body> --------------------编程问答-------------------- TextBox是服务器端控件,必须加runat="server" --------------------编程问答-------------------- TextBox 压根就不能放在<asp:Repeater1>TextBox在此处报错</asp:Repeater1>
里面 --------------------编程问答-------------------- TextBox在Repeater 中,TextBox和Repeater属性中都加了runat="server" --------------------编程问答-------------------- form 标签里面有runat="server"属性吗?我以前也遇到过这种情况,不过加上form标签,写上runat="server"属性,就可以了 --------------------编程问答-------------------- form 有runat="server"属性 --------------------编程问答-------------------- TextBox 压根就不能放在<asp:Repeater1>TextBox在此处报错</asp:Repeater1>
里面,,如何解决?有什么好的方案?
查询编辑保存功能都可以实现,就是我现在要出Excel表遇到问题 --------------------编程问答--------------------
服务器端控件是可以放在Repeater控件里面的。
比如我这边在Repeater里的FooterTemplate项
加了服务器端控件asp:Label ID="lblEmptyText",我们可以在后台这样设置label的值,
protected void repBookDownList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
foreach (RepeaterItem items in repBookDownList.Controls)
{
if (items.ItemType == ListItemType.Footer)
{
((Label)items.FindControl("lblEmptyText")).Text= "text";
}
}
}
其中repBookDownList为Repeater的ID --------------------编程问答-------------------- 感谢luols...不过我采用了另一种方法:使用了 MultiView 和 View 控件
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:TextBox ID="txKjfsBz" runat="server" Text='<%#Eval("BKjfs")%>'></asp:TextBox>
</asp:View>
<asp:View ID="View2" runat="server">
<%#Eval("BKjfs")%>
</asp:View>
</asp:MultiView>
C#
protected void BtnExcel_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
PageHelper.ControlExportExcel(System.Web.HttpContext.Current, this.DetailPanel);
} --------------------编程问答--------------------
--------------------编程问答-------------------- 为你的页面加上
public override void VerifyRenderingInServerForm(Control control)
{
if(!WriteExcel)
base.VerifyRenderingInServerForm(control);
}
然后在你调用 ControlExportExcel 之前将页面级的变量 WriteExcel 设置为 true。
补充:.NET技术 , ASP.NET