473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2330
My recommendation is to add a key in the web.config file. The syntax for
this is:

web.config file:

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

VB.NET code:

ConfigurationSe ttings.AppSetti ngs("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********@hotm ail.com
http://www.nathansokalski.com/

"simon" <me@here.com> wrote in message
news:nf******** *************** *********@4ax.c om...
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********@hot mail.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
3503
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 "Client and Server Scripting in Web Pages" but it only shows server side scripting that is written in HTML in mypage.aspx and not script from...
5
1501
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 page... <%@ Register TagPrefix="dI2" TagName="dartsUC_rolodexsearch" Src="dartsUC_rolodexsearch.ascx" %>
5
1796
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 -- Response.Redirect("MyPage.aspx"); 2) Constants -- Response.Redirect(STRMyPage); // where input parameter is -> const string STRMyPage = "MyPage.aspx"; 3)...
0
1523
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 usercontrol. My problem is that I keep getting a compiler error on the usercontrol variables in my page codebehind (BC30002: Type 'CityGeoPosSelectClass'...
4
2431
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 server-side-include directive: <!-- include virtual="../../foobar.aspx"--> c)When the .stm file is rendered: The .aspx file is included, but it...
2
1411
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 tried changing some simple code in the .cs but the changes do not reflect on the webpage. Someone told me I need to recompile. Is there anywork around?
6
2522
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 SecureQueryString2.vb where I am calling another Class called "InvalidQueryStringException". My problem is where do I put this code so it can be called from...
2
1433
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 beleive this is because I set both to be equal to the same session variable. So when I change the value in test1.name it updates test2.name as well...
4
2206
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 wanted to move my work and needed to place it on the server. Using VS 2005 , went to BUILD -Publish Web Site Checked the box for :: Alow this...
0
7464
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.