By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,258 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,258 IT Pros & Developers. It's quick & easy.

Help referencing a variable in HTML of an aspx page

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.