To Examples
clickcounter4.aspx Source Code
<!-- clickcounter4.aspx Example Keep track of clicks using the Session collection. In this example, refreshing the form sometimes causes a button click. --> <%@ Page Language="C#" Debug="true" %> <script runat=server> public void Page_Load(object sender, EventArgs e) { if (Session[clicks] == null) Session[clicks] = 0; int n = (int) Session[clicks]; txtClicks.Text = n.ToString( ); } public void btnClickMe_Click(object sender, EventArgs e) { int n = 0; // Give n an initial value to prevent // an unitialized variable warning. if (Session[clicks] != null) { n = (int) Session[clicks]; n++; Session[clicks] = n; txtClicks.Text = n.ToString( ); } } </script> <html> <head> <title>clickcounter4.aspx Example</title> <link rel=stylesheet type=text/css href=examples.css /> </head> <body> <h2>clickcounter4.aspx Example</h2> <h2>Keep track of clicks using the Session collection.<br /> Refreshing the form sometimes causes a button click.</h2> <p> <p> <form id=frmClickCounter runat=server> <p>Number of Clicks:<br /> <asp:TextBox runat=server id=txtClicks size=10 Text=0 style=text-align: right; width: 1.5in /></p> <p><asp:Button runat=server id=btnClickMe Text=Click Me style=width: 1.5in; OnClick=btnClickMe_Click /></p> </form> </body> </html>