Asp.net实用技巧(2)

1. 在Asp.net实用技巧(1) 中提到了如何刷新父页面,那么如果要刷新父页面的父页面的父页面了?那就是刷新祖先页面RefreshAncestorPage。

RefreshAncestorPage #region RefreshAncestorPage
/**/ ///

1<summary>   
2![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) ///  刷新指定的祖先页面,注意是"祖先页面"   
3![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif) ///  </summary>

public static void RefreshAncestorPage(HttpResponse Response , string targetPageTitle , bool isCloseCurPage) // targetPageTitle 目标页面的title
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append( "

 1<script language="javascript"> "  );   
 2![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  var p = window ;  "  );   
 3![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  string  .Format(  "  while(p.document.title != '{0}')  "  ,targetPageTitle));   
 4![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  {  "  );   
 5![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  p = p.opener ;  "  );   
 6![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  }  "  );   
 7![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  p.focus();  "  );   
 8![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  p.refresh();  "  );   
 9![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif)   
10![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) if  (isCloseCurPage )   
11![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) ![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif) ![](http://www.cnblogs.com/Images/dot.gif) {   
12![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  window.focus();  "  );   
13![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  window.opener=null;  "  );   
14![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  window.close();  "  );   
15![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif) }    
16![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif)   
17![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) scriptString.Append(  "  </  "  \+  "  script> "  );   
18![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif)   
19![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) Response.Write(scriptString.ToString());   
20![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif) }    
21![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif)   
22![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) ![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif) /**/  /*    
23![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) 需要在Father页面的html中添加如下脚本(在Header中):   
24![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) <script language="javascript">   
25![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) function refresh()   
26![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) {   
27![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) this.location = this.location;   
28![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) }   
29![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) </script>

*/
#endregion

2.如何刷新祖先页面中的某个frame中的page了?

RefreshFrameInAncestorPage #region RefreshFrameInAncestorPage
/**/ ///

1<summary>   
2![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/InBlock.gif) ///  刷新指定的祖先页面中的某个框架的内部页面   
3![](http://zhuweisky.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif) ///  </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>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus