Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find control on aspx from ascx

Tags:

asp.net

vb.net

I'm trying to find a label on an aspx page from a user control (ascx) on said aspx page. Obviously Page.FindControl("lablel1") is not working. Do I need to add in ClientID somewhere? Thanks.

like image 469
halp Avatar asked Nov 28 '22 12:11

halp


1 Answers

I think you ought to stop and think about your design. Your controls should not ever need to know anything about the page that contains them - the fact that you need to go find a control on the page from within another control tells me that you ought to rethink the problem.

The best thing I can tell you (with what little I know of your architecture) is that you ought to pass in a reference to the control you hope to find into your user control. This way your control does not have to know about things outside itself.

like image 198
Andrew Hare Avatar answered Dec 10 '22 05:12

Andrew Hare