Application Object in ASP.NET using VB.NET
his article shows the application object in ASP.NET.
This article shows the application object in ASP.NET.
To manage some information accessible in all the web forms for all the users. The Application object holds information that will be used by many pages in the application (like database connection information). The information can be accessed from any page. The information can also be changed in one place, and the changes will automatically be reflected on all pages.
- Use Lock() and Unlock() method of Application object to handle the dead locks. such as
Create a visit counter for a web form.
Drag a control label on the form.
Form looks like this.
Now double click on the form and add the following code.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ctr As Integer
If Application("vc") Is Nothing Then
ctr = 0
ctr = Convert.ToInt32(Application("vc"))
ctr += 1
Application("vc") = ctr
lblVisitCounter.Text = "You are visitor nummber : #" & ctr
protected void Page_Load(object sender, EventArgs e)
int vc = 0;
if (Application["vc"] != null)
vc = Convert.ToInt32(Application["vc"]);
Application["vc"] = vc;
lblCounter.Text = "You are visitor number : " + vc;
Now save and run the application.
Now copy the address of the running window and open new window and paste the address of first window.
The above example shows that visitor number will be increase every time when you open new window.