All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP+CSS实现打印简单数据报表功能_[PHP教程]
.net生成静态页方法总结_[Asp.Net教程]
二十二 声明 Declarations_[Html教程]
高级自定义查询、分页、多表联合存储过程_[SQL Server教程]
WebService,服务和ajax,使用教程一例_.net资料_编程技术
PHP和MySQL基础教程(二)_[PHP教程]
xhtml+css网页制作教程_[Html教程]
UPDATE注射(mysql+php)的两个模式_php资料_编程技术
PHP连接远程MYSQL和MYSQL5.1中文乱码处理方法_[PHP教程]
PHP学习宝典-第二章_[PHP教程]
Reading number is top 10 pictures
张家界的玻璃桥
NeedWallpaper6
新版武松打虎
Sora aoi in China2
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu1
男人帮杂志里的惹火性感美女2
China railway shunting skills competition
Forced sex girl living abroad2
Wild animals melee moment of life and death1
各种囧况!玩游戏最不喜欢出现的十件事
Download software ranking
Boxer's Top ten classic battle3
Ashlynn Video4
Desire a peach blossom
虚拟机汉化软件
Tram sex maniac 2 (H) rar bag9
Eclipse 4.2.1 For Win32
软件工程思想
仙剑奇侠传98版歌曲
Call Of Duty5
Tram sex maniac 2 (H) rar bag18
qq published in(发表于) 2014/7/9 1:36:06 Edit(编辑)
asp.net2.0中Cache 对象的应用实例

asp.net2.0中Cache 对象的应用实例

asp.net2.0中Cache 对象的应用实例





Cache 对象的应用



本节通过一个简单的实例来介绍如何使用Cache对象在Web页面中添加和移除缓存项。实例运行结果如图1所示。







图1 Cache对象的应用



程序开发步骤如下。



(1)新建一个网站,命名为15_07,其主页默认为Default.aspx。



(2)在Default.aspx页面中添加一个Table表格,用来布局页面,然后在该Table表格中添加一个Label控件和两个Button控件,分别用来显示缓存项信息、执行添加和移除缓存项功能。



(3)程序主要代码如下。



Default.aspx页面中,当用户单击【添加缓存项】按钮时,程序调用Cache对象的Insert方法向该对象中插入一个名称为“cacheExample”的缓存项,并在页面中显示出来。【添加缓存项】按钮的Click事件代码如下:



protected void Button1_Click(object sender, EventArgs e)



{



Cache.Insert("cacheExample", DateTime.Now.ToLongTimeString(), null, DateTime.Now.AddSeconds(30), System. Web. Caching.Cache.NoSlidingExpiration);



showCache();



}



单击【移除缓存项】按钮,程序首先判断指定的缓存项是否存在,如果存在,则调用Cache对象的Remove方法将其移除,并弹出信息提示框,提示用户移除成功;否则,弹出信息提示框,提示用户指定的缓存项不存在。【移除缓存项】按钮的Click事件代码如下:



protected void Button2_Click(object sender, EventArgs e)



{



if (Cache["cacheExample"] != null)



{



Cache.Remove("cacheExample");



Response.Write("");



}



else



Response.Write("");



showCache();



}



完整程序代码如下:



★ ★★★★Default.aspx页面设计文件完整程序代码★★★★★



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>















无标题页


























style="width: 293px; height: 88px">














background-color: #99cccc; text-align: center">标题


























text-align: center">






























text-align: left">



&nbsp; &nbsp; 缓存项信息:






















text-align: left; vertical-align: top;">



&nbsp; &nbsp; &nbsp;







































★ ★★★★Default.aspx.cs页面代码文件完整程序代码★★★★★



using System;



using System.Data;



using System.Configuration;



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;



using System.Web.Caching;



using System.Collections;



public partial class _Default : System.Web.UI.Page



{



protected void Page_Load(object sender, EventArgs e)



{



showCache();



}




















添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.