accessing aspx object from ascx pages and vise verce?

J

John Saunders

rom said:
Is there a better way of doing it, except from using the
session variables?

Depends on what you're asking. What sort of "object" are you referring to?

Keep in mind that both the page and user control are objects of classes. You
can add public properties and events to each. For instance, this allows the
page to pass information to a user control and to subscribe to any events
the user control raises.

John Saunders
 
R

rom

Thanks for the quick response. I'm asking, for example,
about reading the selectedvalue of a dropdownlist that
exists in the aspx page from it's ascx page....

Thanks!
 
J

John Saunders

rom said:
Thanks for the quick response. I'm asking, for example,
about reading the selectedvalue of a dropdownlist that
exists in the aspx page from it's ascx page....

Again, you're talking objects now. :)

How would you handle this if there were some integer inside of object A
wihch you wanted to be able to access from object B? With a property!

However, your user controls are inside of your page. The usual way to handle
this sort of thing is for the container to set the properties of the
contained objects, and not the other way around. For instance, you could add
a ListSelectedIndex property to your user control, and your page could set
it in Page_Load or in the DataBinding event of the user control. If the user
control wanted to be able to change the SelectedIndex, it should expose a
public event. The page could listen for that event and set the SelectedIndex
accordingly. The event arguments would have to pass the new index.

Note how this isolates the page and the control from each other. The page
doesn't have to know _why_ the user control wants the SelectedIndex changed,
and the user control doesn't know anything at all about the DropDownList.
You could even change it to use a different control, and the user control
wouldn't care at all.


John Saunders
 

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
474,266
Messages
2,571,085
Members
48,773
Latest member
Kaybee

Latest Threads

Top