Lock and Unlock the application state in asp.net

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 2238
Add this on your ASPX design page

<asp:Label ID="Label1" runat="server" Font-Size="Larger" ForeColor="Green">
</asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click"
Font-Bold="true" ForeColor="Red" />

Add this on your C# page

protected void Button1_Click(object sender, System.EventArgs e)
{
Application.Lock();

int clickMeCounter = 0;
if (Application["clickMeCounter"] != null)
{
clickMeCounter = (int)Application["clickMeCounter"];
}
clickMeCounter++;
Application["clickMeCounter"] = clickMeCounter;
Application.UnLock();

Label1.Text = "Button Clicked: " + clickMeCounter.ToString() + " times";
}

Comments or Responses

Login to post response