[ASP.NET]如何Response.Redirect新的页面到指定的框架中(原创)

[ASP.NET]如何Response.Redirect新的页面到指定的框架中(原创)
-- LeeWenjie 2006-08-30

博客园帮我解决了工作中不少的疑难问题,从中我也学到了很多很多知识和经验。真诚的感谢那些默默无私奉献的博客们,为IT初学者的快速成长奠定了坚实的基础,今天是我第一次写博客,如果有不妥请多多指教,谢谢 (LeeWenjie:<01Soft.cn@Gmail.com>).

在解决这个问题之前,在网上我看到了很多有关这类问题的解决方法,如:
1、在<Body></body>中增加 <BASE TARGET="framename"> 
或是在 <form id = "forms" action="post" Target="framename" >....</form> (注:framename 为框架页的名称) 
      ---- 适合解决一些当前框架页面无业务逻辑。

2、通过 Response.Write(“<scrpt language='javascript'>....</script>”) 方法中增加相应的脚本语句实现,
     -----当网页使用样式文件布局时,执行完Response.Write()后页面的样式就丢了。

经过一番的思考,假设现有这么一个框架:

<frameset rows="110,*" frameborder="no" border="0" framespacing="0">
  <frame src="FrameTop.aspx" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" />
  <frameset cols="210,*" framespacing="0" frameborder="0" border="0">
  <frame src="FrameLeft.aspx" name="leftFrame" noresize="noresize" id="leftFrame" />
  <frame src="FrameMain.aspx" name="mainFrame" id="mainFrame"/>
  </frameset>
</frameset>

左边框架页(FrameLeft.aspx )有如下两个控件,当下拉发生改变时,对当前页进行业务逻辑处理(调用Btn_Excute的Click事件)后,然后刷新框架mainFrame,或加载指定页其中
__doPostBack('btn_Excute',''); 为ASP.NET为执行页面事件自动生成的脚本..
parent.mainFrame.location.reload():  重新加载MainFrame页面(为JavaScript,语法),
parent.mainFrame.location.href="page.aspx" 
加载指定页面至MainFrame页面(为JavaScript,语法),


<select id="sel_Project" runat="server" onchange=" __doPostBack('btn_Excute','');parent.mainFrame.location.reload();" style=" 96%">
</select>
<asp:Button ID="btn_Excute" runat="server" Text="" OnClick="btn_Excute_Click" Enabled="False" Width="1px" /> 
-----------------------------------------------------------------------------------------------------------------

ASP.NET生成的__doPostBack('btn_Excute',''); 函数:
<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
</script>

 --------------------------------------------------------------------------------------------------------

如有不妥之处,请多多指教,
LeeWenjie 2006-08-20
01Soft.cn@Gmail.com

原文地址:https://www.cnblogs.com/LeeWenjie/p/490125.html