471,066 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

User Control and Variable Question

I am creating a user control for use on several of my pages. I have some
variables that are set on my pages where the user control will be used. I
need my user control to automatically be able to pick up on these variables
and read the values out of them when it is placed on one of these pages. How
is this accomplished? I know I could call a function that is in my user
control and pass it the variable but that would take extra coding for each
page that the user control is placed on and that sort of defeats the purpose
of using them. This needs to be automatic.

Thanks in advance!
May 1 '06 #1
1 1616
In that case your pages that use this control need to inherit from some sort
of base page, or implement some sort of interface. There would then be
methods common to the base page or interface, that the user control could
call. So it would cast its parent page to this base page or interface type,
then access the appropriate property to return the variable value.
That means that a page that doesn't inherit from your base class or
implement the interface would not be able to host the user control.

Another way is to have the a base page class, that has the code in it to set
all the right properties on the user control, or call some method to set
these variables. That way you only write it once. So you define the
variables in the base page class, and write a method to set them that the
base page calls in page_load or whenever is appropriate. Then, the
descendent pages have to set the variable values, but don't have to do it
for the user control because the base page method will do it.

Either way, this is going to require extra coding though.

"David Hearn" <Da*********@shawinc.com> wrote in message
news:u8**************@TK2MSFTNGP02.phx.gbl...
I am creating a user control for use on several of my pages. I have some
variables that are set on my pages where the user control will be used. I
need my user control to automatically be able to pick up on these variables
and read the values out of them when it is placed on one of these pages.
How is this accomplished? I know I could call a function that is in my user
control and pass it the variable but that would take extra coding for each
page that the user control is placed on and that sort of defeats the
purpose of using them. This needs to be automatic.

Thanks in advance!

May 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Lloyd Sheen | last post: by
6 posts views Thread by martin | last post: by
6 posts views Thread by Andrea Williams | last post: by
3 posts views Thread by Dan Nash | last post: by
5 posts views Thread by Dan Nash | last post: by
10 posts views Thread by sqlboy2000 | last post: by
4 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.