asp.net 框架页刷新时如何保留或返回之前的页面
有这样的需求,需要刷新整个框架页的时候,但不希望子页返回默认路径,那就用这个方法吧。
global里加入如下代码:
1
protected
void
Application_BeginRequest(
object
sender, EventArgs e)
2 {
3 Application[ " urlold " ] = Application[ " url " ];
4 if (Request.RawUrl.ToUpper().Contains( " .ASPX " ))
5 {
6 if ( ! Request.RawUrl.ToUpper().Contains( " DEFAULT.ASPX " ))
7 Application[ " url " ] = Request.RawUrl;
8 }
9
10 }
11
2 {
3 Application[ " urlold " ] = Application[ " url " ];
4 if (Request.RawUrl.ToUpper().Contains( " .ASPX " ))
5 {
6 if ( ! Request.RawUrl.ToUpper().Contains( " DEFAULT.ASPX " ))
7 Application[ " url " ] = Request.RawUrl;
8 }
9
10 }
11
框架页的page_load里加入如下代码即可:
1
if
(Application[
"
urlold
"
]
!=
null
)
2 {
3 if (Application[ " urlold " ].ToString().ToLower() != " default.aspx " )
4 lit1.Text = " <script>window.parent.frames[\ " mainFrame\ " ].location.href=\ "" + Application[ " urlold " ] + " \ " </script> " ;
5 }
2 {
3 if (Application[ " urlold " ].ToString().ToLower() != " default.aspx " )
4 lit1.Text = " <script>window.parent.frames[\ " mainFrame\ " ].location.href=\ "" + Application[ " urlold " ] + " \ " </script> " ;
5 }
不算复杂,实现这个效果也可以用cookie,完全通过客户端来实现,也是不错的。偷懒,就用application了。经测试没啥问题