ASP.NET页面传值_第六篇_Cookie
+++ 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_Click(object sender, EventArgs e)
{
Response.Cookies["Name"].Value = TextBox1.Text;
Response.Cookies["Name"].Expires = DateTime.Now.AddDays(1);
HttpCookie aCookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
Response.Redirect("Cookie02.aspx");
}
+++ Cookie02.aspx页面
++ 页面代码如下:
(略)
++ 后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
#region 读取Cookie
if (Request.Cookies["Name"] != null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["Name"].ToString()) + "</br>");
}
if (Request.Cookies["lastVisit"] != null)
{
HttpCookie aCookie = Request.Cookies["lastVisit"];
Response.Write(Server.HtmlEncode(aCookie.Value) + "</br>");
}
#endregion
Response.Write("</br>");
#region 删除Cookie
HttpCookie dCookie;
string cookieName;
int limit = Request.Cookies.Count;
for (int i = 0; i < limit; i++)
{
cookieName = Request.Cookies[i].Name;
dCookie = new HttpCookie(cookieName);
dCookie.Expires = DateTime.Now.AddDays(-1);
&
相关文档:
以下是系统自动生成的回调函数
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.ons ......
关于需要用到的JS文件请到地址:http://d.download.csdn.net/down/2387457/taomanman免费下载;
下面介绍其使用方法:
第一步:
到我提供的地址下载JS文件,并解压到项目某个目录下,你自己定啦。
第二步:
在需要用到时间控件的aspx页面中添加该JS文件中的WdatePicker.js文件。
如<script src="../JS/My97DatePick ......
这两天看《道不远人-----深入解析ASP.NET2.0控件开发》这本书,看完第二章内容后,想总结下“设置自定义ASP.NET服务器控件TagPrefix的几种方法”,以便以后查阅,以下面code编写的控件为例,由于重点不是控件编写,所以写了个非常简单的控件,姑且叫它EmailInput
Code
1using System;
2using ......
/// <summary>
/// 根据指定参数返回BitMap对象
/// 引用如下:
/// using System.Drawing;
/// 调用例子如下:
......
+++ 修改Global.asax文件:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["count"] = 0;
}
void Application_End(object sender, EventArgs e)
{ }
void Application_Error(object sender, EventArgs ......