It shows that you are unregistered. Please register with us by clicking Here
![]() |
|
![]() |
![]() | Register - FAQ - Today's Posts - New Posts - Support - Search | ![]() |
![]() |
![]() |
|
LinkBack | Thread Tools | Display Modes | ![]() |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2006
Age: 48
Posts: 6
|
Hi,
I want to use a single variable in more than one form in my project. Where I have to declare the variable name and its datatype. I like to declare that variable in web.confing Please reply me to my question bye, Gage |
|
|
|
|
|
|
|
#2 (permalink) |
|
Junior Member
Join Date: Jul 2006
Age: 28
Posts: 15
|
To use a global variable or constant to be stored in the web config, you need to add an appSettings tag on your web.config. here a sample:
add the following bellow the <configuration> <appSettings> <add key="GlobalVariable" value="32699456" /> <appSettings> to call this in your web page, for C#: string strVar = System.Configuration.ConfigurationSettings.AppSett ings["GlobalVariable"]. strVar will have a value of "32699456" just add a new line of "add key="<variable>" value="<value>" whenever you want to add any global variables.. |
|
|
|
|
|
#3 (permalink) |
|
Banned User
Join Date: Jul 2006
Location: India
Age: 30
Posts: 105
|
Hi,
For global variable you can use the <app key="varName" value="varValue"> tag in web.config file in your asp.net project. There are some other ways also to declare a global variable. You can also use application or session objects to maintain your data between multiple pages. This is the treditional way to make a variable global, but in asp.net we can also use the web.config setting for global declaration. The important part of using the global var in web.config file is that you can change the values on the fly. Means you dont need to complie your application. Cheers, Amit |
|
|
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Jul 2006
Age: 39
Posts: 8
|
You can use application variables
'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock() 'to retrieve the variable: Dim s as String = Application("MyVar").ToString() or use key in appSettings. You can even use SQL queries: First, include this in your web.config : <appSettings> <add key="myquery1" value="SELECT * FROM dbo WHERE"/> </appSettings> Then, retrieve it with this : Dim myquery1 As String = System.Configuration.ConfigurationSettings.AppSett ings("myquery1") |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| global warming | Geen Engel | All Things General | 11 | 08-09-2006 04:12 PM |
| Can a user browsing my web site read my web.config or Global.asax files? | agaba175 | .NET | 1 | 08-03-2006 12:00 PM |
| Variables on ASP pages | connor | ASP | 1 | 08-01-2006 10:28 AM |
| predefined sections in web.config | Tom Tom | .NET | 0 | 07-11-2006 11:40 PM |