Professional Web Applications Themes
  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. #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

Similar Threads

  1. User control not seen on code beside (behind) page
    By petro in forum ASP.NET Building Controls
    Replies: 2
    Last Post: September 25th, 03:47 PM
  2. user control problem access value from user control to a page
    By gauravkg via DotNetMonster.com in forum ASP.NET Building Controls
    Replies: 3
    Last Post: September 18th, 01:06 AM
  3. Accessing User Control inside Datagrid
    By mirlisa in forum ASP.NET Building Controls
    Replies: 1
    Last Post: July 4th, 01:32 PM
  4. User Control - Accessing Properties from the Container Page
    By Sumeet Mahajan in forum ASP.NET Building Controls
    Replies: 0
    Last Post: March 2nd, 09:08 AM
  5. Accessing Web User Control from code behind
    By Michael Morse in forum ASP.NET Building Controls
    Replies: 1
    Last Post: January 24th, 12:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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