473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 1721
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lloyd Sheen | last post by:
Is there any one who has actually done this. I have now scanned more web articles about this with the realization that not one of them (including MSDN docs) outlines how to do this. This is...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
7
by: Gene | last post by:
I have a number of aspx pages on which a single user control appears. All of the aspx pages and the user control make user of code-behind modules. I need for logic in the user control's code-behind...
6
by: Andrea Williams | last post by:
When I step through my code, the ASPX Page_Load happens before the Page_Load in the User Control. This means that the property values are not set to their defaults yet in the User Control and all...
3
by: Dan Nash | last post by:
Hi I'm new to C#, moving from ASP, and slightly confused so bear with me! Basically I've got 4 pages, each of which runs the same user control (some header information). I want to be able to...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
This may be a stupid question but... How do I programmtically access the page's request.querystring value in a custom user control. I tried doing this in the page_load routine of the user...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.