User Controls

G

Guest

Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a Variable name of "Public string Fred" in the control, will the page that uses the control be able to see this global variable or is there something that I need to do to make it available to the page which uses the control

Thanks in advance for your assistance!!!!
 
J

John Saunders

Jim Heavey said:
Hello, I have a user control which I place at the top of each page. I
want to have code in this user control which sets the value of a couple of
module variables and I was wondering if I create a Variable name of "Public
string Fred" in the control, will the page that uses the control be able to
see this global variable or is there something that I need to do to make it
available to the page which uses the control?

Jim, all due respect, but many of your recent questions suggest you might
want to pick up a book on ASP.NET. In particular, one of the greatest
advances of ASP.NET over ASP is the fact that it uses OO techniques.

Modules are not an OO technique. You should immediately stop using them and
start finding OO alternatives. In the .NET world, modules should be used
only as containers of global, shared methods, and not for data at all. A
module is nothing much more than a public class all of whose members are
public and Shared. Using such a class instead of a module will make it much
clearer that, for instance, all of the variable members will be shared by
all users, ans shared without any synchronization as well.
 
G

Guest

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.
 
G

Guest

User control can have properties that the hosting page can set and get.

If you want it event driven, then you could make use of events that the user control raise and any interested objects i.e. the hosting pages, could 'get' the value in the user control in the form of event arg

Hope this helps

Good luck...
 
C

clintonG

The QUE MCAD Training Guides are very good as they cover
each aspect of developing ASP.NET, controls, and XML Web Services.
Do the exercises which cover a wide range of objective tasks. I've
favored those for C# three of which were authored by Amit Kahlani
who did a very good job. Finally, you'll get a lot more out of
articles posted to the various focus group websites once you have
a training guide that covers eask aspect of development.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



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.
 
J

John Saunders

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.
 

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,019
Latest member
RoxannaSta

Latest Threads

Top