473,503 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a code behind variable from ASPX

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
Nov 18 '05 #1
3 2527
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.
Nov 18 '05 #2
What is your variable name, and what datatype did you declare it to be?

Jeff

"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:O3*************@TK2MSFTNGP14.phx.gbl...
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

Nov 18 '05 #3
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" <rt*****@stgeorgeconsulting.com> wrote in message
news:O3***************@TK2MSFTNGP14.phx.gbl...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2782
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
1
4371
by: Arthur | last post by:
I have a mix web site, ASP and ASPX files. I have assigned a value to Session("Date") and the href to an ASPX page. When I further href to another ASP Page. The content in Session("Date") becoming...
3
2006
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
5
14731
by: Vinod Kumar | last post by:
Hi All, Can I access a Javascript function written in an ASP.NET from the codebehind (C#) of that page? If yes, kindly give the code snippet to do this. Thanks and Regards Vinod Kumar
1
3108
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
5
1497
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
6
2600
by: Martin Eyles | last post by:
Hi, I have a .aspx page which has a .ascx file included through the lines <%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %> and <aspcustom:menu id="Menu1"...
3
2528
by: TB | last post by:
On a user control (ascx) I have a datagrid with a hyperlink column containing the following code: <asp:HyperLinkcolumn headerstyle-width="80px" ItemStyle-Width="80px" DataNavigateUrlField="ID"...
8
10802
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.