Click here to Skip to main content
15,893,588 members
Articles / Web Development / ASP.NET

Caching in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.79/5 (204 votes)
21 Feb 2004CPOL6 min read 704.8K   10.9K   214  
An overview of caching in ASP.NET.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Caching
{
	/// <summary>
	/// Summary description for DataCaching.
	/// </summary>
	public class DataCaching : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.HyperLink HyperLink2;
		protected System.Web.UI.WebControls.Label Label1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Cache["textvalue"] !=null)
				Label2.Text="Previous value:" + Cache["textvalue"].ToString();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{			
			Cache["textvalue"]=TextBox1.Text;
		}
	}
}

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 Code Project Open License (CPOL)


Written By
The Code Project
United States United States
Smitha is a software developer, and has been in the industry since January 2000. She has experience in ASP.NET, C#, Windows Forms, Visual Basic, ASP, JavaScript, VBScript, and HTML. She has been with CodeProject since 2003 and currently works as Senior Editor.

In her free time, she tries out new dishes, reads a little, and puts together jigsaw puzzles. Originally from Trivandrum, Smitha currently lives with her husband and fellow CP'ian Nish [^] and her son Rohan in Columbus, Ohio.

Comments and Discussions