accessing page variable from user control code behind

G

Gerald

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
 
C

Chris R. Timmons

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top