Click here to Skip to main content
15,881,172 members
Articles / Web Development / IIS

Cache, Session, and ViewState

Rate me:
Please Sign up or sign in to vote.
3.62/5 (28 votes)
21 Jul 2008GPL35 min read 164K   1.1K   50  
Properly using cache, session, and viewstate objects in your asp.net application
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CachePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Cache["Name"] != null)
            {
                LblCacheVariable.Text = Cache["Name"].ToString();
            }
            else
            {
                LblCacheVariable.Text = "NULL";
            }
        }
    }
    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        Cache["Name"] = TBName.Text;
        LblCacheVariable.Text = Cache["Name"].ToString();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Web Developer ProgTalk
United States United States
C# Developer dealing with Microsoft .Net languages and frameworks. View more of my articles at Prog Talk

Comments and Discussions