我做了绑定的功能,绑定手机后显示的都是关于这部手机的资料,然取消绑定在有的IE6浏览器不能撤底的清除,还会留下一个空字符,但在火狐上不会,请高手指教下 HttpCookie phonebind = new HttpCookie("phonebind");//新建Cookie
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["phonebind"] != null)//如果这个Cookie值不为空
{
Panel1.Visible = false;//不显示手机绑定框
Panel2.Visible = true;//就显示他已经绑定的手机型号 phonename.Text = Request.Cookies["phonebind"].Value;//显示他已经绑定的手机型号
}
else
{
Panel2.Visible = false;
Panel1.Visible = true;
}
}
}
protected void Button1_Click(object sender, EventArgs e)//绑定手机型号事件
{
phonebind.Value = DropDownList3.SelectedValue;//DropDownList控件所选的值
DateTime now = DateTime.Now;
phonebind.Expires = now.AddHours(1);
Response.Cookies.Add(phonebind);//生成Cookie
Response.Redirect(Request.Url.ToString());//返回页面
}
protected void LinkButton1_Click(object sender, EventArgs e)//取消绑定事件
{
string aa = Request.Cookies["phonebind"].Value;
phonebind.Expires = DateTime.Now;
Response.AppendCookie(phonebind);
Panel2.Visible = false;
Panel1.Visible = true;
Response.Redirect(Request.Url.ToString());
}好久了,一直搞不明白为什么, IE不行火狐倒没问题
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["phonebind"] != null)//如果这个Cookie值不为空
{
Panel1.Visible = false;//不显示手机绑定框
Panel2.Visible = true;//就显示他已经绑定的手机型号 phonename.Text = Request.Cookies["phonebind"].Value;//显示他已经绑定的手机型号
}
else
{
Panel2.Visible = false;
Panel1.Visible = true;
}
}
}
protected void Button1_Click(object sender, EventArgs e)//绑定手机型号事件
{
phonebind.Value = DropDownList3.SelectedValue;//DropDownList控件所选的值
DateTime now = DateTime.Now;
phonebind.Expires = now.AddHours(1);
Response.Cookies.Add(phonebind);//生成Cookie
Response.Redirect(Request.Url.ToString());//返回页面
}
protected void LinkButton1_Click(object sender, EventArgs e)//取消绑定事件
{
string aa = Request.Cookies["phonebind"].Value;
phonebind.Expires = DateTime.Now;
Response.AppendCookie(phonebind);
Panel2.Visible = false;
Panel1.Visible = true;
Response.Redirect(Request.Url.ToString());
}好久了,一直搞不明白为什么, IE不行火狐倒没问题
phonebind.Expires = DateTime.Now; 变成
phonebind.Expires = DateTime.Now.getDay()-1;
试试!
HttpCookie cookie = Request.Cookies["phonebind"];
Response.Cookies.Remove("phonebind");
cookie.Expires = DateTime.Now.AddDays(-100);
cookie.Path = "/";
Response.Cookies.Add(cookie);