[英]Same ID error while adding dynamic controls to table in ASP .NET
I have added controls dynamically to a table in ASP .NET by letting user enter the required no of rows. 通过让用户输入所需的行数,我将控件动态添加到ASP.NET中的表。 The sample code of the addRow() function is:
addRow()函数的示例代码为:
HtmlTableCell cell_1 = new HtmlTableCell();
HtmlTableCell cell_2 = new HtmlTableCell();
l = new Label();
nomenclature = new TextBox();
unit = new TextBox();
row[i] = new HtmlTableRow();
label.Text = "" +(i+ 1);
cell_1.Controls.Add(l);
row[i].Controls.Add(cell_1);
nomenclature.TextMode = TextBoxMode.MultiLine;
nomenclature.Rows = 5;
nomenclature.Columns = 40;
nomenclature.ID="nomenclature"+i;
nomenclature.Text = "NA";
cell_2.Controls.Add(nomenclature);
row[i].Controls.Add(cell_2);
table_items.Controls.Add(row[i]);
Now after successfully adding the rows, when i refresh the page and again try to add new Rows, It gives me sameID ' nomenclature0 ' error. 现在成功添加行,当我刷新页面,然后再次尝试添加新行,它给了我sameID“nomenclature0”的错误。
Please help me regarding this, 请帮助我
Thanks in Advance, 提前致谢,
I havent enough info about your code. 我没有关于您的代码的足够信息。
Two possible solutions: 两种可能的解决方案:
1) Try this "table_items.Controls.Clear();" 1)试试这个“ table_items.Controls.Clear();” before call addRows Function.
在调用addRows函数之前。
2) if ispostback, dont fill table. 2)如果是ispostback,请不要填写表格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.