Accessing a code behind variable from ASPX

Discussion in 'ASP .Net' started by Ryan Taylor, Nov 24, 2004.

  1. Ryan Taylor

    Ryan Taylor Guest

    Hi.

    I need to be able to access a public code behind variable within my ASPX
    page. The reason is that I have a user control "Header" which defines a
    table layout, and is included in all my pages, at various levels in the
    website heirarchy. The table requires a background image. My images folders
    is at the root of the website, effectively "~/images/". I need the
    background image to show whether I at a page in the root of my website or in
    some other directory a few folders down. Normally, I could just write
    "~/images/image.jpg" if I was in a code behind file, but I cannot use this
    syntax in the ASPX page. So, I have a "VirtualRoot" public variable declared
    in my Header.cs file, and this variable is assigned Request.ApplicationPath
    on the Page_Load event. This will give me the appropropriate path to prefix
    /images/image.jpg. But I cannot remember how to access this variable from
    the ASPX page. Any ideas?

    Thanks in advance.
    Ryan
     
    Ryan Taylor, Nov 24, 2004
    #1
    1. Advertising

  2. Ryan Taylor

    Ryan Taylor Guest

    Ok. I've managed to solve the problem in another way, I've made the table
    server side and added the attribute directly. Though, I would like to know
    how to do what I initially asked.
     
    Ryan Taylor, Nov 24, 2004
    #2
    1. Advertising

  3. Ryan Taylor

    Jeff Dillon Guest

    What is your variable name, and what datatype did you declare it to be?

    Jeff

    "Ryan Taylor" <> wrote in message
    news:O3Qt#...
    > Hi.
    >
    > I need to be able to access a public code behind variable within my ASPX
    > page. The reason is that I have a user control "Header" which defines a
    > table layout, and is included in all my pages, at various levels in the
    > website heirarchy. The table requires a background image. My images

    folders
    > is at the root of the website, effectively "~/images/". I need the
    > background image to show whether I at a page in the root of my website or

    in
    > some other directory a few folders down. Normally, I could just write
    > "~/images/image.jpg" if I was in a code behind file, but I cannot use this
    > syntax in the ASPX page. So, I have a "VirtualRoot" public variable

    declared
    > in my Header.cs file, and this variable is assigned

    Request.ApplicationPath
    > on the Page_Load event. This will give me the appropropriate path to

    prefix
    > /images/image.jpg. But I cannot remember how to access this variable from
    > the ASPX page. Any ideas?
    >
    > Thanks in advance.
    > Ryan
    >
    >
     
    Jeff Dillon, Nov 24, 2004
    #3
  4. Can you make that public variable a property of the user control, assign the
    user control an id, & then access it with <usercontrolid>.<propertyname> ?

    --
    Ben Strackany
    www.developmentnow.com

    <a href="http://www.developmentnow.com">dn</a>


    "Ryan Taylor" <> wrote in message
    news:O3Qt%...
    > Hi.
    >
    > I need to be able to access a public code behind variable within my ASPX
    > page. The reason is that I have a user control "Header" which defines a
    > table layout, and is included in all my pages, at various levels in the
    > website heirarchy. The table requires a background image. My images

    folders
    > is at the root of the website, effectively "~/images/". I need the
    > background image to show whether I at a page in the root of my website or

    in
    > some other directory a few folders down. Normally, I could just write
    > "~/images/image.jpg" if I was in a code behind file, but I cannot use this
    > syntax in the ASPX page. So, I have a "VirtualRoot" public variable

    declared
    > in my Header.cs file, and this variable is assigned

    Request.ApplicationPath
    > on the Page_Load event. This will give me the appropropriate path to

    prefix
    > /images/image.jpg. But I cannot remember how to access this variable from
    > the ASPX page. Any ideas?
    >
    > Thanks in advance.
    > Ryan
    >
    >
     
    Ben Strackany, Nov 24, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    643
    Alphonse Giambrone
    Jun 28, 2003
  2. Mark Fitzpatrick
    Replies:
    2
    Views:
    3,831
    =?Utf-8?B?QWxleCBNYWdoZW4=?=
    Apr 24, 2004
  3. Paolo Pignatelli
    Replies:
    6
    Views:
    2,231
    Paolo Pignatelli
    Feb 21, 2005
  4. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    527
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  5. Jason
    Replies:
    0
    Views:
    141
    Jason
    Oct 6, 2005
Loading...

Share This Page