473,326 Members | 2,076 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; read value from hosting aspx code-behind

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 to read the current value of a
variable in the hosting aspx page's code-behind. How is this accomplished?

Thanks.
Nov 18 '05 #1
7 883
From your user control code-behind you can use code similar to this:

If Page.SomePublicProperty = "Whatever" Then ...

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Gene" <Mr******@jw.com> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl...
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 to read the current value of a
variable in the hosting aspx page's code-behind. How is this accomplished?

Thanks.

Nov 18 '05 #2
On the page make sure it's public

From the control, something like
string myVar = this.ParentPage.variableName.ToString();

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl...
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 to read the current value of a
variable in the hosting aspx page's code-behind. How is this accomplished?

Thanks.

Nov 18 '05 #3
Thanks Curt and Steve: Now a related question: I set the public variable
from the aspx page_load event procedure, and want to I read that public
variable from the page_load event procedure of the user control. In order
for this to work as expected, I need for the page_load event of the aspx to
fire *before* the page_load of the user control. Is that a safe assumption?

Thanks again.

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
On the page make sure it's public

From the control, something like
string myVar = this.ParentPage.variableName.ToString();

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl...
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 to read the current value of

a variable in the hosting aspx page's code-behind. How is this accomplished?
Thanks.


Nov 18 '05 #4
put in a break point and test it to see.
You may need to move it up to the intialize event though

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
Thanks Curt and Steve: Now a related question: I set the public variable
from the aspx page_load event procedure, and want to I read that public
variable from the page_load event procedure of the user control. In order
for this to work as expected, I need for the page_load event of the aspx to fire *before* the page_load of the user control. Is that a safe assumption?
Thanks again.

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
On the page make sure it's public

From the control, something like
string myVar = this.ParentPage.variableName.ToString();

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl...
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 to read the current value
of a variable in the hosting aspx page's code-behind. How is this accomplished?
Thanks.



Nov 18 '05 #5
I've tried the initial task using the syntax both you and Steve recommended,
however, either way I get compile-time errors, the message of which is
something like:
'System.Web.UI.Page' does not contain a definition for 'myPublicVariable'

It makes sense that such compile-time errors would occur, as the user
control - at compile time - does not know which aspx page will be hosting
it, and the compiler therefore cannot know where to look to see if the
public property exists. Am I confused? Is it possible to do this without
getting the compile-time error and I'm just missing something.

Thanks.


"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
put in a break point and test it to see.
You may need to move it up to the intialize event though

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
Thanks Curt and Steve: Now a related question: I set the public variable
from the aspx page_load event procedure, and want to I read that public
variable from the page_load event procedure of the user control. In order
for this to work as expected, I need for the page_load event of the aspx to
fire *before* the page_load of the user control. Is that a safe

assumption?

Thanks again.

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
On the page make sure it's public

From the control, something like
string myVar = this.ParentPage.variableName.ToString();

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl...
> 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 to read the current
value of
a
> variable in the hosting aspx page's code-behind. How is this

accomplished?
>
> Thanks.
>
>



Nov 18 '05 #6
newVar = ((YourPage)Page).publicVariableName.ToStirng();
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
I've tried the initial task using the syntax both you and Steve recommended, however, either way I get compile-time errors, the message of which is
something like:
'System.Web.UI.Page' does not contain a definition for 'myPublicVariable'

It makes sense that such compile-time errors would occur, as the user
control - at compile time - does not know which aspx page will be hosting
it, and the compiler therefore cannot know where to look to see if the
public property exists. Am I confused? Is it possible to do this without
getting the compile-time error and I'm just missing something.

Thanks.


"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
put in a break point and test it to see.
You may need to move it up to the intialize event though

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.com> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
Thanks Curt and Steve: Now a related question: I set the public variable from the aspx page_load event procedure, and want to I read that public variable from the page_load event procedure of the user control. In order for this to work as expected, I need for the page_load event of the
aspx
to
fire *before* the page_load of the user control. Is that a safe

assumption?

Thanks again.

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
> On the page make sure it's public
>
> From the control, something like
> string myVar = this.ParentPage.variableName.ToString();
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "Gene" <Mr******@jw.com> wrote in message
> news:O5**************@TK2MSFTNGP11.phx.gbl...
> > 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 to read the current

value
of
a
> > variable in the hosting aspx page's code-behind. How is this
accomplished?
> >
> > Thanks.
> >
> >
>
>



Nov 18 '05 #7
Hello Gene,
see if the public property exists. Am I confused? Is it possible to do
this without getting the compile-time error and I'm just missing
something.


Derive your own page class.

Ex:

public class MyPage : System.Web.UI.Page
{
public string myPublicVariable; // Note: I would never make this as a field in production code. This is just to illustrate.
}

From your user control:

MyPage myPage = (MyPage)this.Page;
string s = myPage.myPublicVariable;

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #8

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

Similar topics

3
by: Amir Eshterayeh | last post by:
Dear Friends Would you please give me your professional idea about this asp.net problem. I need different virtual directory for different customer with their names like these:...
0
by: Merkisson Jourhanssen | last post by:
I will be using LoadControl to add user control to aspx page at runtime. The user control hosts a server control (custom menu component) which requires property setting to display menu correctly: ...
4
by: Barb | last post by:
I have a user control as my Save button for my page. When the Save button is clicked, I want some client-side validation to take place from a javascript function in the page, and then I'd like the...
2
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
0
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Frankie | last post by:
I have a user control into which I insert a bunch of controls dynamically. I have it all working just fine - Everything is there on Postback, etc. I load this user control into a hosting ASPX...
5
by: Norsoft | last post by:
I have a .Net 1.1 application which is downloaded into an aspx page. It is a dll which inherits from System.Windows.Forms.UserControl. It works fine on a PC with only the 1.1 Framework. However,...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.