Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > accessing page variable from user control code behind

Reply
Thread Tools

accessing page variable from user control code behind

 
 
Gerald
Guest
Posts: n/a
 
      07-04-2003
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{
public class myWebBase : System.Web.UI.Page {
public String myVar = "I'm there";
}
}

Then I have the page:

namespace myAPP{
public class pageTemplate : myWebBase {
.......
}
}

Now I have a user control I add dynamically into the page:

namespace myAPP.controls{

public class clsWebBaseControl : System.Web.UI.UserControl {
//I would like to be able to access the variable "myVar" I declared in
the first cs file.
}
}

How ca I do that.
I tried : Parent.Page.myVar but it is not recognised.

Could someone help me?

Thanks

Gerald





 
Reply With Quote
 
 
 
 
Chris R. Timmons
Guest
Posts: n/a
 
      07-04-2003
"Gerald" <> wrote in
news:#:

> 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{
> public class myWebBase : System.Web.UI.Page {
> public String myVar = "I'm there";
> }
> }
>
> Then I have the page:
>
> namespace myAPP{
> public class pageTemplate : myWebBase {
> .......
> }
> }
>
> Now I have a user control I add dynamically into the page:
>
> namespace myAPP.controls{
>
> public class clsWebBaseControl : System.Web.UI.UserControl {
> //I would like to be able to access the variable "myVar" I
> declared in
> the first cs file.
> }
> }
>
> How ca I do that.
> I tried : Parent.Page.myVar but it is not recognised.


Gerald,

Try casting Parent.Page:

myWebBase myPage = (myWebBase) Parent.Page;
myPage.myVar = "Hello, world!";


Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing a code-behind variable from a user control TB ASP .Net 3 07-12-2007 01:48 AM
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
Accessing Web User Control Values From ASPX Code Behind Jason ASP .Net Web Controls 0 10-06-2005 07:19 PM
Accessing User Control properties from C# Code Behind... Jon Ratcliffe ASP .Net Building Controls 2 04-23-2004 08:53 AM
Accessing Web User Control from code behind Michael Morse ASP .Net Building Controls 0 01-23-2004 06:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57