How to declared the Global variables in web.config in asp.net ? - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > .NET » How to declared the Global variables in web.config in asp.net ?


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 07-06-2006   #1 (permalink)
gage
Junior Member
 
Join Date: Jul 2006
Age: 48
Posts: 6
Default How to declared the Global variables in web.config in asp.net ?

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
gage is offline   Reply With Quote


Old 07-07-2006   #2 (permalink)
AddCoderPro
Junior Member
 
Join Date: Jul 2006
Age: 28
Posts: 15
Default

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..
AddCoderPro is offline   Reply With Quote

Old 07-08-2006   #3 (permalink)
agaba175
Banned User
 
Join Date: Jul 2006
Location: India
Age: 30
Posts: 105
Default Global Variables

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
agaba175 is offline   Reply With Quote

Old 07-10-2006   #4 (permalink)
Minakshi
Junior Member
 
Join Date: Jul 2006
Age: 39
Posts: 8
Default

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")
Minakshi is offline   Reply With Quote

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


footer left
All times are GMT. The time now is 12:47 AM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Mortgage Calculator | Personal Loan | Advertising | Myspace Proxy | Modded Xbox

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49