具有动态 gridviewrow 的namingContainer ID
这不会是对我的问题的一个非常清楚的解释,但我不知道如何更好地解释它。
我有一个在 PreInit 上动态创建的 gridview。该网格视图在每一行上动态添加文本框。
每次按下按钮时,我都会在 gridview 单元格内循环并获取文本框的文本 - 并更新数据库。
第一次创建 gridview 时,行的 uniqueID 如下所示: ctl03、ctl04、ctl05、ctl06(因此,文本框 ID 为 ctl03$txt0 等。)
我第一次按下按钮时,行 UniqueID 仍然相同,以便我可以通过 FindControl(ID) 方法找到控件,或使用 Request.Form[txt.UniqueID]
但是;第一次之后,每当我按下按钮时,都会创建如下所示的 ClientId 行:ctl02、ctl03、ctl04、ctl05..,这样我就找不到文本框,也无法捕获写在上面的文本。
当我查看渲染的 HTML 代码时,我发现 rowClientID 仍然与第一个创建的相同(ctl03、ctl04、ctl05、ctl06)
有谁知道为什么 rowID(命名容器 ID)在第一次更新后发生变化?
提前致谢。
This will not be a very clear explanation of my problem, but I don't know how to explain it better.
I have a gridview which I create dynamically on PreInit. This gridview has textboxes dynamically added on each row.
Everytime I push the button, I loop inside the gridview cells and get the Text of the textboxes -and update the database.
the first time the gridview is created, row uniqueID's are like this:
ctl03, ctl04, ctl05, ctl06 (thus, the textbox ID's are ctl03$txt0 etc..)
The first time I push the button, the row UniqueID's are still the same, so that I can find the controls by FindControl(ID) method, or using Request.Form[txt.UniqueID]
However; after the first time, whenever I push the button, the row ClientId's are created like the following: ctl02, ctl03, ctl04, ctl05.. So that I cannot find the Textboxes and cannot catch the Text written on them.
When I look at the rendered HTML code, I see that the rowClientID's are still the same with the first created ones (ctl03, ctl04, ctl05, ctl06)
Does anyone have any idea why the rowIDs (naming container IDs) change after the first update?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解决方案是使用静态 ID 创建文本框,而不是让其由 ASP.NET 动态创建。如果您使用 asp.net ver 4,则可以完成此操作。
其他解决方案是仅渲染一个简单的
然后在回发时,您只需使用旧方式捕获返回并获取值。
最后,TextBox只不过是输入的呈现,加上一些对其写入内容的检查,包括Anti-XSS安全。
One solution is to create your textboxes with static ids and not let it dynamic create by asp.net. This can be done if you use asp.net ver 4.
Other solution is to just render a simple
<input name="KnowName01" id="KnowId01" type="text" value="your value here" maxlength="100" etc... >
and then on post back you just capture the return with the old way and get the value.
At the end, the TextBox is nothing more than a render of the input, plus some checks for what write on it, including Anti-XSS safe.