473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Help referencing a variable in HTML of an aspx page

hello,
what i'm looking to do is store the path of the app on a the server
for reuse in the site.
my thoughts so far are...
-make a key in the web.config file
-retrieve the value in globals.asax in application startup
-store it in a variable that can be reference from all pages
-use that variable on many pages
my questions
1) what is the syntax of the lines in global.asax page to put this
value into a variable that is accessible to other site pages
2) what is the syntax of using a variable in an aspx page (that may or
may not be part of a .net object - straight html).
for example to use this variable as the first part of a path..
<% rootDir %> & 'images/logo.gif'

thanks for any tips

Feb 8 '06 #1
2 2313
My recommendation is to add a key in the web.config file. The syntax for
this is:

web.config file:

<configuration>
<appSettings>
<add key="baseURL" value="http://localhost/WebApplication1" />
</appSettings>

VB.NET code:

ConfigurationSettings.AppSettings("baseURL")
If you don't want to use the web.config file, you can place it in the
Global.asax.vb file as part of the Global class. You would declare the
variable the same as any other variable that you want to share with other
classes, so you would need to use an appropriate Access Modifier, such as
Public (there are others, look at them to see which one is most appropriate
for your use and are most comfortable with). Here is an example:

Public Const baseurl As String = "http://localhost/WebApplication1"
Public Shared baseurl2 As String = "http://localhost/WebApplication1"

Whether you want to make it a Const is your choice. When you use a constant,
the compiler replaces the anywhere you use the variable with the actual
value, so if you were to ever change the value of the Const you would need
to recompile any code that uses the variable as well (depending on how you
have your code organized this may or may not affect you, and it depends on
whether you expect to ever need to change the value of the Const). Either
way, to access the variable, use this code:

Global.baseurl
Global.baseurl2

I recommend, as I said earlier, the web.config method, it is used more often
for things of this sort. However, the choice is obviously up to you. Good
Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"simon" <me@here.com> wrote in message
news:nf********************************@4ax.com...
hello,
what i'm looking to do is store the path of the app on a the server
for reuse in the site.
my thoughts so far are...
-make a key in the web.config file
-retrieve the value in globals.asax in application startup
-store it in a variable that can be reference from all pages
-use that variable on many pages
my questions
1) what is the syntax of the lines in global.asax page to put this
value into a variable that is accessible to other site pages
2) what is the syntax of using a variable in an aspx page (that may or
may not be part of a .net object - straight html).
for example to use this variable as the first part of a path..
<% rootDir %> & 'images/logo.gif'

thanks for any tips

Feb 9 '06 #2
thank you very much for your reply and advice.

On Thu, 9 Feb 2006 00:03:33 -0500, "Nathan Sokalski"
<nj********@hotmail.com> wrote:
My recommendation is


Feb 9 '06 #3

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

Similar topics

4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
5
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...
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
0
by: N. Demos | last post by:
Hello, I have a custom usercontrol, of which I have two instances of in my aspx page. Both the usercontrol and page have codebehind. In the page codebehind, I want a member variable for each...
4
by: TWEB | last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some guidance with resolving. Here's the problem: a) I have a .stm file. b) I referenc a .aspx file on this .stm file using a...
2
by: Joshua Tan | last post by:
hey there, I really need some help with this. I have a web application running on Windows 2000 Server , IIS5.0 , .Net Framework 1.1 I have a file.aspx, file.aspx.cs and file.aspx.resx I...
6
by: momo | last post by:
Guys I need your help on this. I have this one problem and I admitted I am a novice at this. This is a Code Behind in an aspx page. You will see where I have the plus signs below in...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
4
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.