如何将实际控件存储在列表中?
长话短说,我想将动态加载的用户控件粘贴到引用已加载的实际对象的列表中。这样我就可以进入列表并从用户控件中提取结果。我想使用 mycontrol.GetResult() ,然后它将引用该控件并从已填写的表单中获取结果,结果将以字符串形式返回。我不希望它初始化相同类型的新控件,因为那样我将无法收到结果。有什么建议吗?
谢谢!
Long story short, I would like to take my usercontrols that are loaded dynamically and stick them into a list that references the actual object that has been loaded. So I can go into the list and pull results from the usercontrol. I would like to use mycontrol.GetResult() and it will then reference the control and grab the results from the form that has been filled out, which the results will be returned as a string. I do not want it to initialize a new control of the same type because I will not be able to receive my results then. Any suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需创建一个控件列表:
然后您可以使用该列表根据需要引用每个控件(这是一个简单的示例......您填充列表的代码很可能会更复杂)。
Just create a list of Controls:
You can then use that list to reference each of the controls as needed (this is a simple example...your code to populate the list will most likely be more complicated).
谁以编程方式添加控件?页面还是用户控件?该组件可以做到这一点。否则,另一个技巧是用户控件动态加载其他用户控件。您可以为页面提供一个接口定义,例如具有 List 类型的 IDynamicControlHolder,并在动态控件(或其他位置)中执行操作。
Who adds the controls programmatically? THe page or a user control? That component could do it. Otherwise, another trick is say a user control dynamically loads other user controls. You could give the page an interface definition say IDynamicControlHolder that has a List type, and do in the dynamic control (or somewhere else).
因此,我已经创建了类似的代码并将控件加载到列表中,但我不确定如何从放回对象的表单中获取结果。看到代码示例后,我意识到我已经在这样做了,所以必须有更好的方法来获得我想要的东西。我操纵了现有的方法之一,现在当用户进入验证屏幕时,我使用它将结果加载到我的对象中。这很好用,谢谢你确认我做得对。
So I already had similar code created and the controls loaded into a list but I was not sure how to get the results from the forms placed back into my object. After seeing code examples I realized I was already doing that so there had to be a better way to get what I want. I manipulated one of my existing methods and now I use it to load the results into my object when the user goes to the verification screen. This works great, thank you for confirming for me I was doing it right.