asp.net 框架页刷新时问题

2012 年 10 月 2 日5,2820

欢迎进入.NET社区论坛,与300万技术人员互动交流 >>进入

asp.net 框架页刷新时如何保留之前的页面

假如框架页右边是 right.aspx,打开的页面是newPage.aspx

right.aspx

protected void Page_Load(object sender, EventArgs e)

{

HttpCookie cookie;

if (Request.Cookies["getUrl"] != null)

{

cookie = Request.Cookies["getUrl"];

if (cookie["url"].ToString()。ToLower() != "right.aspx")

Response.Write("<script>parent.document.all['right'].src = \"" + cookie["url"] + "\";</script>");

}

}

-------------------------

common.cs

public static void setCookie(string url)

{

HttpCookie getUrl = new HttpCookie("getUrl");//声明cookie

getUrl.Values.Add("url", url);//将url保存到cookie中

//getUrl.Expires = DateTime.Now.AddDays(1);//设置COOKIE过期事件为1天,不设置保存时间,这样浏览器关闭COOKIE就失效

HttpContext.Current.Response.Cookies.Add(getUrl);//确定写入cookie中

}

----------------------

newPage.aspx

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

string url = Request.RawUrl;// Request.UrlReferrer.ToString();//这个得到左边的

url = url.Substring(url.LastIndexOf('/') + 1);

common.setCookie(url);

}

【责编:peter】

0 0