1. 在Asp.net实用技巧(1) 中提到了如何刷新父页面,那么如果要刷新父页面的父页面的父页面了?那就是刷新祖先页面RefreshAncestorPage。
RefreshAncestorPage #region RefreshAncestorPage
/**/ ///
1<summary>
2 /// 刷新指定的祖先页面,注意是"祖先页面"
3 /// </summary>
public static void RefreshAncestorPage(HttpResponse Response , string targetPageTitle , bool isCloseCurPage) // targetPageTitle 目标页面的title
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append( "
1<script language="javascript"> " );
2 scriptString.Append( " var p = window ; " );
3 scriptString.Append( string .Format( " while(p.document.title != '{0}') " ,targetPageTitle));
4 scriptString.Append( " { " );
5 scriptString.Append( " p = p.opener ; " );
6 scriptString.Append( " } " );
7 scriptString.Append( " p.focus(); " );
8 scriptString.Append( " p.refresh(); " );
9
10 if (isCloseCurPage )
11   {
12 scriptString.Append( " window.focus(); " );
13 scriptString.Append( " window.opener=null; " );
14 scriptString.Append( " window.close(); " );
15 }
16
17 scriptString.Append( " </ " \+ " script> " );
18
19 Response.Write(scriptString.ToString());
20 }
21
22  /**/ /*
23 需要在Father页面的html中添加如下脚本(在Header中):
24 <script language="javascript">
25 function refresh()
26 {
27 this.location = this.location;
28 }
29 </script>
*/
#endregion
2.如何刷新祖先页面中的某个frame中的page了?
RefreshFrameInAncestorPage #region RefreshFrameInAncestorPage
/**/ ///
1<summary>
2 /// 刷新指定的祖先页面中的某个框架的内部页面
3 /// </summary>
public static void RefreshFrameInAncestorPage(HttpResponse Response , string ancestorTitle , string frameName , string targetUrl , bool isCloseCurPage) // targetPageTitle 目标页面的title
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append( "
1<script language="javascript"></script>