473,396 Members | 2,154 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,396 software developers and data experts.

How to grab a variable from a user control from the parent page

I have a usercontrol that sets some public variables.

I can grab this variable from another usercontrol like this:

ctype(Page, templatePage).UC_getVariables.globalMenuCategory

This works fine because the control setting the variable is processed before
the control reading the variable.

The catch is that I now want to read this variable from the parent page. The
issue is that the parent page code is executed PRIOR to the userControl that
sets the variable. So I'm not returning a value.

Is there any way around this? If not, I'm guessing the solution is to simply
migrate the UC code that sets the variables into my parent page's
codebehind.

-Darrel
Nov 18 '05 #1
2 2615
Darrel,
Make sure that any calculations or things that are going on in the
control are not done in the Page_Load event. Override the OnPreRender event
and perform the calculations and manipulations there. Then you'll be able to
pickup the values in the page.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Darrel" <no*****@nospam.com> wrote in message
news:u$****************@TK2MSFTNGP12.phx.gbl...
I have a usercontrol that sets some public variables.

I can grab this variable from another usercontrol like this:

ctype(Page, templatePage).UC_getVariables.globalMenuCategory

This works fine because the control setting the variable is processed
before the control reading the variable.

The catch is that I now want to read this variable from the parent page.
The issue is that the parent page code is executed PRIOR to the
userControl that sets the variable. So I'm not returning a value.

Is there any way around this? If not, I'm guessing the solution is to
simply migrate the UC code that sets the variables into my parent page's
codebehind.

-Darrel

Nov 18 '05 #2
> Darrel,
Make sure that any calculations or things that are going on in the
control are not done in the Page_Load event. Override the OnPreRender
event and perform the calculations and manipulations there. Then you'll be
able to pickup the values in the page.


Hmm...I wrote a Page_PreRender() sub, but couldn't get that to work.

However, moving the function from the page_load to page_init solved the
problem. Is that an acceptable solution?

-Darrel
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerald | last post by:
Hi all, I have a aspx page that inherits from a cs class which is common for all pages in my application. In that cs file, I define some veriable. IE: the webBasePage.cs: namespace MyAPP{
8
by: darrel | last post by:
I'm still trying to fully understand how best to pass variables between pages/usercontrols/each other. On a current site I've done, I've had one userControl do the logic and set the variable,...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
0
by: darrel | last post by:
I have a user control that sets a public shared variable that I then access from the parent page: projectclass.controlclass.thevariable the problem I'm finding is that if I have the variable...
1
by: David Lozzi | last post by:
Hello, I have a user control that saves data. When the data is saved, I need to call a function in the parent page from the user control to initiate something else. I know I can set it up so...
2
by: engwar1 | last post by:
I have a page that my users will go to to upload files to my website. As I want to reuse the file upload code on multiple pages I put the file upload textbox/buttons on a user control which I plan...
1
by: David Hearn | last post by:
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...
3
by: tshad | last post by:
I am trying to put together a user control (.ascx). Can you access an outside control from it? My control: login2.ascx ****************************************************************...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.