473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2416
From your user control code-behind you can use code similar to this:

If Page.SomePublic Property = "Whatever" Then ...

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Gene" <Mr******@jw.co m> wrote in message
news:O5******** ******@TK2MSFTN GP11.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.T oString();

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.co m> wrote in message
news:O5******** ******@TK2MSFTN GP11.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_da rkfalz.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
On the page make sure it's public

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

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.co m> wrote in message
news:O5******** ******@TK2MSFTN GP11.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.co m> wrote in message
news:OT******** ******@tk2msftn gp13.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_da rkfalz.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
On the page make sure it's public

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

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.co m> wrote in message
news:O5******** ******@TK2MSFTN GP11.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 'myPublicVariab le'

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_da rkfalz.com> wrote in message
news:ug******** ******@TK2MSFTN GP11.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.co m> wrote in message
news:OT******** ******@tk2msftn gp13.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_da rkfalz.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
On the page make sure it's public

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

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.co m> wrote in message
news:O5******** ******@TK2MSFTN GP11.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 ).publicVariabl eName.ToStirng( );
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Gene" <Mr******@jw.co m> wrote in message
news:%2******** *********@tk2ms ftngp13.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 'myPublicVariab le'

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_da rkfalz.com> wrote in message
news:ug******** ******@TK2MSFTN GP11.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.co m> wrote in message
news:OT******** ******@tk2msftn gp13.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_da rkfalz.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
> On the page make sure it's public
>
> From the control, something like
> string myVar = this.ParentPage .variableName.T oString();
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "Gene" <Mr******@jw.co m> wrote in message
> news:O5******** ******@TK2MSFTN GP11.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.P age
{
public string myPublicVariabl e; // 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.Pa ge;
string s = myPage.myPublic Variable;

--
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
1737
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: www.oursite.com/Jack www.oursite.com/Sue www.oursite.com/Tom
0
1043
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: // In user control set property of custom menu to be value of myInt myCustomMenuServerControl.Orientation = myInt; Value of myInt must come from hosting aspx page. 1. In what event of hosting aspx page should I have LoadControl call? (Init?
4
4478
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 server event to fire to update the database. I've successfully done this with a normal webcontrol via: myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');" In that case, myControl is an asp:button on the page. In the...
2
1964
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 some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
0
1924
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 some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
3
2227
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 some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
2
4815
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 page at runtime during the Page_Load event procedure of the hosting ASPX page. Question: Would it be better to load the user control from the hosting page's OnInit event rather than Page_Load? Does it matter or not? I ask because I understand...
5
2056
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, the control will not load on a PC with the 2.0 Framework installed. I know that IE will use the newest framework so I assume it is a security issue. At the assembly level I apply the following attributes;
5
4075
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 both projects. Both controls(dlls) have been signed using SN.exe and I've set up the appropriate .Net assembly permissions using those Strong Names The DLL's have been copied to the /bin directory in both web virtual directories.
33
11838
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 (NT_AUTHORITY\SYSTEM). I understand that when the service starts, no user may be logged in, but that's ok, as the app I am monitoring can only be run by a logged in user. Do I need to use WMI to get the user context of Explorer.exe or is there a...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.