Mac
Mac

Reputation: 7543

Accessing control created dynamically in code behind

i have a link button which i have created dynamically and added it to a div i want to access this link button in some other function in code behind how to do this

Upvotes: 2

Views: 2082

Answers (3)

Alexander Beletsky
Alexander Beletsky

Reputation: 19841

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.

Upvotes: 1

Marko
Marko

Reputation: 1924

If you have defined your control properly(with id) you can access it without a problem in the next request. 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...

Hope this helps

Marko

Upvotes: 1

Related Questions