I have the feeling that i'm missing something key here.
I've tried following guides on http://msdn.microsoft.com/en-us/magazine/cc300437.aspx and on google, but i can't see what i haven't done.
I have some very basic code which i have written just trying to get this to work:
The Default.aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableSessionState="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Demo Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="myLabel" runat="server" Text="foo"></asp:Label>
<asp:LinkButton ID="lnkClickButton" runat="server" OnClick="lnkClickButton_Click" CommandName="Clicky">Click Me</asp:LinkButton>
</div>
</form>
</body>
</html>
The Default.aspx.cs code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["clickcount"] = 0;
Cache["clickscount"] = 0;
}
protected void lnkClickButton_Click(object sender, EventArgs e)
{
Session["clickcount"] = (int)Session["clickcount"] + 1;
Cache["clickscount"] = (int)Cache["clickscount"] + 1;
Label myLabel = ((Label)this.FindControl("myLabel"));
if (myLabel != null)
{
myLabel.Text = "Session: " + Session["clickcount"] + "; Cache: " + Cache["clickscount"] + ";";
}
}
}
I've tried using both the session object and the cache object to increment the values, but to no avail. I just get 1 every time.
N.B. this is my first asp.net project, also i'm fairly new to c#.