Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to Declare and Use Application Variables in ASP.Net

Author: DevASP
Download Source Code : 324_app_variable.zip

In ASP.net application variables are very useful application variables are use for the counter of visitors of sites and also for the other purpose and these are very easy to declare and use.

In this simple example you will learn to declare and use of application variables. Firstly create a webform and place a label having text Enter Value, a textbox with name txtvalue. Then create a button having text save and finally create a button with text goto form2.

 

<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 344px; POSITION: absolute; TOP: 24px" runat="server" Width="80px" Height="24px" Font-Size="Large">Devasp</asp:Label>

 

<asp:TextBox id="TXTVALUE" style="Z-INDEX: 103; LEFT: 160px; POSITION: absolute; TOP: 152px" runat="server" Height="32px" Width="104px"></asp:TextBox>

 

<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 72px; POSITION: absolute; TOP: 200px" runat="server" Height="24px" Width="64px" Text="SAVE"></asp:Button>

 

<asp:Button id="Button2" style="Z-INDEX: 105; LEFT: 72px; POSITION: absolute; TOP: 256px" runat="server" Height="32px" Width="128px" Text="GOTO FORM2"></asp:Button>

  • Now write code on button1 click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        Application("VALUE1") = TXTVALUE.Text

 

End Sub

  • Now insert code on button2 click event

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

 

        Server.Transfer("WEBFORM2.ASPX")

 

End Sub

  • Now insert another form and create two labels on that form

<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 56px" runat="server" Width="192px" Height="32px" DESIGNTIMEDRAGDROP="21" Font-Size="Large" BackColor="Silver"> STORED VALUE</asp:Label>

 

<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 264px; POSITION: absolute; TOP: 56px" runat="server" Width="360px" Height="32px" Font-Size="Large" BackColor="#E0E0E0"></asp:Label>

  • Now write code on form2 load event

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

      Label2.Text = Application("VALUE1")

 

End Sub

  • This statement is for declare and set value of the application variable

Application("VALUE1") = TXTVALUE.Text

 

In this statement value1 is the name of the application variable.

 

Note: This value is stored when ever the server is online on which your website is hosted and it is accessable for the new user also.

 

Article Comments
Any imports ??

Posted on 3/4/2010 7:39:43 PM by El Coco

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How To Declare and Use Global Variables in your ASP.Net Web Application

Disclaimer - Privacy
© 2002-2012 DevASP.net