当前位置:编程学习 > asp >>

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

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);
}


作者:luojianfeng
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,