Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing a code behind variable from ASPX

Reply
Thread Tools

Accessing a code behind variable from ASPX

 
 
Ryan Taylor
Guest
Posts: n/a
 
      11-24-2004
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


 
Reply With Quote
 
 
 
 
Ryan Taylor
Guest
Posts: n/a
 
      11-24-2004
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.


 
Reply With Quote
 
 
 
 
Jeff Dillon
Guest
Posts: n/a
 
      11-24-2004
What is your variable name, and what datatype did you declare it to be?

Jeff

"Ryan Taylor" <(E-Mail Removed)> wrote in message
news:O3Qt#(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Ben Strackany
Guest
Posts: n/a
 
      11-24-2004
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" <(E-Mail Removed)> wrote in message
news:O3Qt%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie - variable from code-behind to aspx page Damiano Callegari ASP .Net 3 01-09-2006 08:04 PM
Accessing Web User Control Values From ASPX Code Behind Jason ASP .Net Web Controls 0 10-06-2005 07:19 PM
How to bring aspx code (in HTML view) to the aspx.vb code-behind? Paolo Pignatelli ASP .Net 6 02-21-2005 01:55 AM
Re: Accessing UserControls in ASPX code-behind pages Mark Fitzpatrick ASP .Net 2 04-24-2004 05:16 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments