ASP.NET页面传值_第九篇_Cache
+++ PassDatatableByCache01.aspx页面
++ 页台代码如下:
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="用Cache传数据集"></asp:Button>
++ 后台代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string connStr = "Data Source=ora11g;uid=scott;pwd=tiger;unicode=true";
string sqlStr = "SELECT * from EMP";
OracleDataAdapter da = new OracleDataAdapter(sqlStr, connStr);
DataTable dt = new DataTable();
da.Fill(dt);
Cache.Insert("statistic", dt,
null,
DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration);
Response.Redirect("PassDatatableByCache02.aspx");
}
+++ PassDatatableByCache02.aspx页面
++ 页面代码如下:
(略)
++ 后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (Cache.Get("statistic") != null)
{
DataTable dt = (DataTable)Cache.Get("statistic");
foreach (DataRow dr in dt.Rows)
{
Response.Write(dr[0].ToString() + "</br>");
}
}
else
{
Response.Write("Cache缓存中没有内容!");
}
}
+++ 说明
(1) 本例用Cache传递数据集;
(2) 用Cache传递数据集要比Session可行得多,Cache使用更灵活,而且可以设置过期时间或是缓存依赖;
(3) 在本BLOG的Cache分类中有Cache的详尽使用。
相关文档:
以下是系统自动生成的回调函数
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.ons ......
学习ASP.NET中的Application、Session、Cookie
1.Application建立的变量,在系统内部任何地方都可以访问,通常网站地访问统计可能会用的较多。如果要用到Application首先在VS2005中建立一个global.asa文件。例如我们要写一个网站访问数量的统计的话,在global.asa中先声明变量iCount。如下所示:
  ......
protected void Page_Load(object sender, EventArgs e)
{
}
#region OnPreInit 第一步
protected override void OnPreInit(EventArgs e)
{
//检查 ......
方法
数据量
生命期
作用域
位置
Application
任意大小
整个应用程序
所有用户
服务端
Cache
任意大小
根据需要设定
所有用户
服务端
Cookie
简单数据
根据需要设定
单个用户
客户端
Session
简单数据
用户活动时间+延迟时间(20分钟)
单个用户
服务端
Web.Config
极少改变简单数据
直到改变配 ......
+++ Cookie01.aspx页面
++ 页面代码如下:
<asp:TextBox ID="TextBox1" runat="server" ForeColor="Red" Width="182px">Name</asp:TextBox>
<asp:Button ID="BtnCookie" runat="server" OnClick="BtnCookie_Click" Text="BtnCookie" /><br />
++ 后台代码如下:
protected void BtnCookie_Cl ......