accessing aspx control from ascx

R

rom

Hi,

I have an aspx page with header as user control, footer as
user control, and 2 other user controls inside the page.

I'm trying to access a seleted value of a dropdownlist the
exists in the main aspx page from one of the user
controls. I know it's possible because I reached it by
using debug and it exists with the value in here:

directcast(page.controls(3).controls
(19),dropdownlist).selectedvalue

but, of course, this is not a way to solve things....
How can I do this correctly?

Thanks.
 
A

Anders Norås

I'm trying to access a seleted value of a dropdownlist the
exists in the main aspx page from one of the user
controls. I know it's possible because I reached it by
using debug and it exists with the value in here:

You can access the controls on the page via the Page property of the
UserControl like this:
Control control=Page.FindControl("MyControl");

However, I suggest that you redesign your application because UserControls
should not depend on controls in it's container (Page in your example).

Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top