ASP.net - 在代码中添加控件,如何通过 FindControl() 获取它?
我在代码中创建一个表格,添加行,然后添加单元格。每个单元格中都有一个复选框,其中包含我设置的 ID。
我将此表添加到更新面板中,稍后我想找出用户已选中/未选中的复选框。
我不知道最好的方法,所以我所做的是创建一个检查按钮。我保留了对复选框的引用,并尝试更改代码中的选中值,但这并没有更新我的网页。我认为一旦将其添加到代码中,它就会丢失引用。
所以我尝试使用Page.FindControl并传递了我给它的原始ID,但它没有找到它。我猜这是因为它在将 ID 添加到页面之前在 ID 之前放置了一堆废话...
所以基本上,我该怎么做来检查我添加的复选框是否已更改? CheckedChange 事件也不起作用。
I create a table in code, add rows and then cells to it. In each cell there is a checkbox which has an ID I set.
I add this table to an updatepanel, and later on I want to find out which checkboxes the user has checked/unchecked.
I don't know the best way, so what I did was create a button that checks. I kept a reference to the checkboxes, and tried changing the checkedvalue in code, but this did not update my webpage. I figure it loses the reference once it is added in code.
So I tried to use Page.FindControl and passed the original ID I gave it, but it doesn't find it. I am guessing this is because it puts a load of crap before the ID before adding it to the page...
So basically, what do I do to check the if the checkboxes I added have been altered or not? A CheckedChange event didn't work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能必须使用递归FindControl
You may have to use a recursive FindControl