ImageButton必须放在具有 runat=server 的窗体标记内
我想在后台用代码自动添加imagebutton数组,代码如下:protectedvoidPage_Load(objectsender,EventArgse){seatse...
我想在后台用代码自动添加imagebutton数组,代码如下:
protected void Page_Load(object sender, EventArgs e)
{
seatsettion();
}
public void seatsettion()
{
int i = 0;
int j = 0;
int count = 0;
int n = 0;
ImageButton[] ibtnArray = new ImageButton[181];
Panel pl = new Panel();
for (i = 0; i < 15; i++)
{
count = 0;
for (j = 0; j < 14; j++)
{
for (n = 1; n <= 180; n++)
{
ibtnArray[n] = new ImageButton();
ibtnArray[n].ImageUrl = "~/pics/sofat1.png";
pl.Controls.Add(ibtnArray[n]);
}
/* count = count + 1;
if ((count == 4) || (count == 10))
{
continue;
}
ibtnArray[n].ImageUrl = "~/pics/sofat1.png";
*/
}
this.Controls.Add(pl);
}
之后,运行,出现了类型““ImageButton”的控件“ctl299899”必须放在具有 runat=server 的窗体标记内。”的错误。
于是,我改了代码:
<html runat="server">
<head runat="server">
<title></title>
</head>
<body runat="server">
<form id="form1" runat="server">
</form>
</body>
</html>
把能添runat="server"的地方都填上,结果还是报这个错。请问该如何解决,谢谢! 展开
protected void Page_Load(object sender, EventArgs e)
{
seatsettion();
}
public void seatsettion()
{
int i = 0;
int j = 0;
int count = 0;
int n = 0;
ImageButton[] ibtnArray = new ImageButton[181];
Panel pl = new Panel();
for (i = 0; i < 15; i++)
{
count = 0;
for (j = 0; j < 14; j++)
{
for (n = 1; n <= 180; n++)
{
ibtnArray[n] = new ImageButton();
ibtnArray[n].ImageUrl = "~/pics/sofat1.png";
pl.Controls.Add(ibtnArray[n]);
}
/* count = count + 1;
if ((count == 4) || (count == 10))
{
continue;
}
ibtnArray[n].ImageUrl = "~/pics/sofat1.png";
*/
}
this.Controls.Add(pl);
}
之后,运行,出现了类型““ImageButton”的控件“ctl299899”必须放在具有 runat=server 的窗体标记内。”的错误。
于是,我改了代码:
<html runat="server">
<head runat="server">
<title></title>
</head>
<body runat="server">
<form id="form1" runat="server">
</form>
</body>
</html>
把能添runat="server"的地方都填上,结果还是报这个错。请问该如何解决,谢谢! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询