非模态页面刷新父页面实现

原理:在子页面调用父页面中的方法,该方法刷新父页面:

父页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <script type="text/javascript">
      var resh = function () {
          alert("父页面刷新了!");
          location.reload()
      }
      var open1 = function () {
          //window.open("DefaultFrom.aspx");
          window.open("DefaultFrom.aspx", "", "width=400,height=400");
          //window.open('DefaultFrom.aspx', 'newwindow', 'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') 

      }
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <input type="button" value="弹出非模态页面" onclick="open1()" />
    </div>
    </form>
</body>
</html>


子页面前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultFrom.aspx.cs" Inherits="DefaultFrom" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="点击按钮提交后,关闭当前页面并刷新父页面" />
    
    </div>


    <script type="text/javascript">
    '<%if(isSubmit) {%>'
        window.opener.resh();
        window.close();
   ' <%} %>'
    </script>
    
    </form>
</body>
</html>

后台

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DefaultFrom : System.Web.UI.Page
{
    protected bool isSubmit = false;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        isSubmit = true;
    }
}

 

posted on 2013-01-07 12:38  Lucifer_007  阅读(213)  评论(0编辑  收藏  举报