Pages

Wednesday, 28 September 2011

asp.net application state example: how to lock and unlock application state in asp.net


<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        Application.Lock();
       
        int clickCounter = 0;
        if(Application["ClickCounter"] !=null)
        {
            clickCounter = (int)Application["ClickCounter"];
        }
        clickCounter++;
        Application["ClickCounter"] = clickCounter;
        Application.UnLock();
        Label1.Text = "Button Clicked: " + clickCounter.ToString() + " times";
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net application state example: how to lock and unlock application state in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">asp.net application state example: Lock and UnLock</h2>
        <asp:Label
            ID="Label1"
            runat="server"
            Font-Size="Large"
            ForeColor="DodgerBlue"
            >
        </asp:Label>
        <br /><br />
        <asp:Button
            ID="Button1"
            runat="server"
            Text="Show Button Click Status"
            OnClick="Button1_Click"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment