简体   繁体   English

访问在代码背后动态创建的控件

[英]Accessing control created dynamically in code behind

我有一个链接按钮,它是我动态创建的并将其添加到div中的,我想在如何执行此操作的代码中的其他功能中访问此链接按钮

If you have defined your control properly(with id) you can access it without a problem in the next request. 如果您已正确定义控件(使用id),则可以在下一个请求中毫无问题地访问它。 But...if you want to access it in the same request, it is not rendered yet, so you need to define your control as a private field in your code behind in order to be able to access it outside your initialization/addToDiv function... 但是...如果要在同一请求中访问它,则尚未呈现它,因此您需要在代码后面将控件定义为私有字段,以便能够在初始化/ addToDiv函数之外访问它...

Hope this helps 希望这可以帮助

Marko 马尔科

As you create it dynamically, you are able to keep reference to this control as your page protected/private member. 动态创建它时,您可以保留该控件作为页面受保护/私有成员的引用。 And access control by this reference. 并通过此参考进行访问控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM