Monday, 30 July 2012

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


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


  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.     protected void Button1_Click(object sender, System.EventArgs e) {  
  7.         Application.Lock();  
  8.           
  9.         int clickCounter = 0;  
  10.         if(Application["ClickCounter"] !=null)  
  11.         {  
  12.             clickCounter = (int)Application["ClickCounter"];  
  13.         }  
  14.         clickCounter++;  
  15.         Application["ClickCounter"] = clickCounter;  
  16.         Application.UnLock();  
  17.   
  18.         Label1.Text = "Button Clicked: " + clickCounter.ToString() + " times";  
  19.     }  
  20. </script>  
  21.   
  22. <html xmlns="http://www.w3.org/1999/xhtml">  
  23. <head id="Head1" runat="server">  
  24.     <title>asp.net application state example: how to lock and unlock application state in asp.net</title>  
  25. </head>  
  26. <body>  
  27.     <form id="form1" runat="server">  
  28.     <div>  
  29.         <h2 style="color:Red">asp.net application state example: Lock and UnLock</h2>  
  30.         <asp:Label   
  31.             ID="Label1"   
  32.             runat="server"   
  33.             Font-Size="Large"   
  34.             ForeColor="DodgerBlue"  
  35.             >  
  36.         </asp:Label>  
  37.         <br /><br />  
  38.         <asp:Button   
  39.             ID="Button1"   
  40.             runat="server"   
  41.             Text="Show Button Click Status"  
  42.             OnClick="Button1_Click"  
  43.             Font-Bold="true"  
  44.             ForeColor="DodgerBlue"  
  45.             />  
  46.     </div>  
  47.     </form>  
  48. </body>  
  49. </html>  

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home