accessing page variable from user control code behind

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default accessing page variable from user control code behind

    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 Guest

  2. Similar Questions and Discussions

    1. User control not seen on code beside (behind) page
      Can someone shed some light on how to get this user control to work? I created a simple user control with several properties (I want to access...
    2. user control problem access value from user control to a page
      Thanks a lot for paying attention to my problem , i tell u the problem i have a main form in which i gave a login label that points to a...
    3. Accessing User Control inside Datagrid
      I've created a simple user control (dynamically populated dropdown list via database) and dynamically added it to a datagrid. There are 9 instances...
    4. User Control - Accessing Properties from the Container Page
      Dear all, Please check my problem - Problem: I have created a User Control(UC1) for navigating between pages. There are 4 buttons on the user...
    5. Accessing Web User Control from code behind
      How come I am unable to access the properties and methods of my Web User Control from the codebehind of an aspx page Any ideas how how to do this...
  3. #2

    Default Re: accessing page variable from user control code behind

    "Gerald" <gege107@hotmail.com> wrote in
    news:#AzbZaiQDHA.704@tk2msftngp13.phx.gbl:
    > 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.
    [url]http://www.crtimmonsinc.com/[/url]
    Chris R. Timmons Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139