accessing page variable from user control code behind

Discussion in 'ASP .Net' started by Gerald, Jul 4, 2003.

  1. Gerald

    Gerald Guest

    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
     
    Gerald, Jul 4, 2003
    #1
    1. Advertisements

  2. Gerald,

    Try casting Parent.Page:

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


    Hope this helps.

    Chris.
     
    Chris R. Timmons, Jul 4, 2003
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.