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

/**////<summary>
///刷新指定的祖先页面,注意是"祖先页面"
///</summary>
publicstaticvoidRefreshAncestorPage(HttpResponseResponse,stringtargetPageTitle,boolisCloseCurPage)//targetPageTitle目标页面的title


{
StringBuilderscriptString=newStringBuilder();
scriptString.Append("<scriptlanguage=javascript>");
scriptString.Append("varp=window;");
scriptString.Append(string.Format("while(p.document.title!='{0}')",targetPageTitle));
scriptString.Append("{");
scriptString.Append("p=p.opener;");
scriptString.Append("}");
scriptString.Append("p.focus();");
scriptString.Append("p.refresh();");

if(isCloseCurPage)


{
scriptString.Append("window.focus();");
scriptString.Append("window.opener=null;");
scriptString.Append("window.close();");
}

scriptString.Append("</"+"script>");

Response.Write(scriptString.ToString());
}


/**//*
需要在Father页面的html中添加如下脚本(在Header中):
<scriptlanguage="javascript">
functionrefresh()
{
this.location=this.location;
}
</script>
*/
#endregion
2.如何刷新祖先页面中的某个frame中的page了?
RefreshFrameInAncestorPage
#regionRefreshFrameInAncestorPage

/**////<summary>
///刷新指定的祖先页面中的某个框架的内部页面
///</summary>
publicstaticvoidRefreshFrameInAncestorPage(HttpResponseResponse,stringancestorTitle,stringframeName,stringtargetUrl,boolisCloseCurPage)//targetPageTitle目标页面的title


{
StringBuilderscriptString=newStringBuilder();
scriptString.Append("<scriptlanguage=javascript>");
scriptString.Append("varp=window;");
scriptString.Append(string.Format("while(p.document.title!='{0}')",ancestorTitle));
scriptString.Append("{");
scriptString.Append("p=p.opener;");
scriptString.Append("}");
scriptString.Append("p.focus();");
scriptString.Append(string.Format("p.{0}.location='{1}';",frameName,targetUrl));

if(isCloseCurPage)


{
scriptString.Append("window.focus();");
scriptString.Append("window.opener=null;");
scriptString.Append("window.close();");
}

scriptString.Append("</"+"script>");

Response.Write(scriptString.ToString());
}
#endregion
3.如何刷新本页面中的其它框架了?
RefreshTargetFrameInSamePage
#regionRefreshTargetFrameInSamePage

/**////<summary>
///从某一框架刷新同一页面中的任意一框架(包括自己所处的框架)
///</summary>
publicstaticvoidRefreshTargetFrameInSamePage(HttpResponseResponse,stringframeName,stringtargetUrl)


{
stringscripStr=string.Format("<scriptlanguage='javascript'>window.parent.{0}.location='",frameName)+targetUrl+"'";
scripStr+="</"+"script>";
Response.Write(scripStr);
}
#endregion
4.如何调用祖先页面的脚本?
CallAncestorScriptMethod
#regionCallAncestorScriptMethod

/**////<summary>
///调用祖先页面中的某个框架内部page的脚本,如果是调用祖先页面的脚本,targetFrameName传入null
///</summary>
publicstaticvoidCallAncestorScriptMethod(HttpResponseResponse,stringtargetPageTitle,stringtargetFrameName,stringmethodName,string[]paraStrs)


{
StringBuilderscriptString=newStringBuilder();
scriptString.Append("<scriptlanguage=javascript>");
scriptString.Append("varp=window;");
scriptString.Append(string.Format("while(p.document.title!='{0}')",targetPageTitle));
scriptString.Append("{");
scriptString.Append("p=p.opener;");
scriptString.Append("}");
if(targetFrameName!=null)


{
if(paraStrs==null)


{
scriptString.Append(string.Format("p.frames['{0}'].{1}();",targetFrameName,methodName));
}
else


{
stringrParaStr=string.Format("'{0}'",paraStrs[0]);
for(inti=1;i<paraStrs.Length;i++)


{
rParaStr+=string.Format(",'{0}'",paraStrs[i]);
}
scriptString.Append(string.Format("p.frames['{0}'].{1}({2});",targetFrameName,methodName,rParaStr));
}
}
else


{
if(paraStrs==null)


{
scriptString.Append(string.Format("p.{0}();",methodName));
}
else


{
stringrParaStr=string.Format("'{0}'",paraStrs[0]);
for(inti=1;i<paraStrs.Length;i++)


{
rParaStr+=string.Format(",'{0}'",paraStrs[i]);
}
scriptString.Append(string.Format("p.{0}({1});",methodName,rParaStr));
}

}

scriptString.Append("</"+"script>");
Response.Write(scriptString.ToString());
}
#endregion
5.如何调用本页面中其它框架page的脚本?
CallTargetFrameScriptMethodInSamePage
#regionCallTargetFrameScriptMethodInSamePage

/**////<summary>
///调用本页面中其它框架内部page的脚本,
///</summary>
publicstaticvoidCallTargetFrameScriptMethodInSamePage(HttpResponseResponse,stringtargetFrameName,stringmethodName,string[]paraStrs)


{
StringBuilderscriptString=newStringBuilder();
scriptString.Append("<scriptlanguage=javascript>");

if(paraStrs==null)


{
scriptString.Append(string.Format("window.parent.{0}.{1}();;",targetFrameName,methodName));
}
else


{
stringrParaStr=string.Format("'{0}'",paraStrs[0]);
for(inti=1;i<paraStrs.Length;i++)


{
rParaStr+=string.Format(",'{0}'",paraStrs[i]);
}
scriptString.Append(string.Format("window.parent.{0}.{1}({2});;",targetFrameName,methodName,rParaStr));
}

scriptString.Append("</"+"script>");
Response.Write(scriptString.ToString());
}
#endregion
可见上述这些功能都是通过脚本完成的,如果对脚本不熟悉,是不可能做好Web开发的!