Application Object in ASP.NET using VB.NET

his article shows the application object in ASP.NET.
  • 1940

This article shows the application object in ASP.NET.

Application Object

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


For example:

Create a visit counter for a web form.

Drag a control label on the form.

Form looks like this.


Figure 1.

Now double click on the form and add the following code.

VB 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"))

        End If

        ctr += 1



        Application("vc") = ctr



        lblVisitCounter.Text = "You are visitor nummber : #" & ctr

    End Sub


C# code:


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.


Figure 2.

Now copy the address of the running window and open new window and paste the address of first window.


Figure 3.

The above example shows that visitor number will be increase every time when you open new window.


More Articles

© 2020 DotNetHeaven. All rights reserved.