|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help referencing a variable in HTML of an aspx pagehello,
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 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! Show quoteHide quote "simon" <m*@here.com> wrote in message news:nfgku11qnb5nk0kv95g8mmndel58kjttma@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 > thank you very much for your reply and advice.
On Thu, 9 Feb 2006 00:03:33 -0500, "Nathan Sokalski" <njsokal***@hotmail.com> wrote: Show quoteHide quote >My recommendation is
IsNumeric Bug or misunderstanding?
Are people using data binding now? Accessing embedded resources Upgrading VB2003 to 2005 how to do Binding with code what's the difference Function parameter function sorting inherited BindingList Strange behavior data-bound combobox VB Project security violation on new Workstation |
|||||||||||||||||||||||