Jim Heavey said:
Thanks for your comments.
I am sorry to say that I have a number of books on ASP.Net. I have
"Professional ASP.Net 1.0" which provides little insight to how to use User
Controls. It provides nothing in terms of how to use Javascript with
ASP.Net controls (another of my questions).
I think my question is a fair question. If I am going to be using a User
Control and that User control has to retrieve information from the database.
This information control how the page will operate. If I retrieve this
information within the control, how can I provide that information to the
page which contains the control. The book that I have does not discuss this
issue, and I am sure I could pick up atleast 12 other books which do not as
well.
If you would care to recommend a book, please do. If you care to point
out how I might be able to use an OO technique for this issue, by all means
do not restrain your self.
Jim, sorry to reply so late, but you've received useful responses in the
meantime.
The basic concept is that user controls are classes. Anything you learn
which applies to classes applies to user controls.
In particular, you are correct that you could load the data inside of the
user control. You could then expose the data to the outside world by adding
a public read-only property to the user control which would expose the data.
It could be of type DataSet, for instance.
You could also do it the other way around. Have the "caller" of the user
control load the data and then pass the data to the user control. Again,
this could be done via a property, though this time, it wouldn't be
read-only.
Depending on the nature of the data, you might want to use a more general
type than DataSet for the data being passed. For instance, making it of type
IEnumerable would allow you to pass almost anything into the user control,
which means that the data source could change without requiring the user
control to change.