机制和Httpcontext相似。
缓存主要是为了提高效率。
传值页前台代码:
<asp:TextBox ID="txtbValue" runat="server"></asp:TextBox>
<asp:Button ID="btnReturnValue" runat="server" OnClick="btnReturnValue_Click" Text="传递值" />
传值页后台代码:
protected void btnReturnValue_Click(object sender, EventArgs e)
{
string name = txtbValue.Text;
Context.Cache["name"] = name;
Response.Redirect("cache.aspx");
}
接收页后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (Context.Cache["name"] != null)
{
Response.Write(Context.Cache["name"]);
}
}
注意:缓存可能会被清空,所以在输出前一定要先判断他是否为空。// if (Context.Cache["name"] != null)