现在有一个页面A,是显示数据的的,用datagrid load出来,这个页面 有一个按钮(实现对数据库插入数据功能),现在我要点击按钮的话,就弹出一个窗口B,在里面填写要插入的字段以后,就关闭他,然后A页面重新刷新一次,就可以看见刚刚看见那个数据了,这样怎么实现呀,谢谢指点(就是说B页面出入数据以后,A就重新刷新一次了)

解决方案 »

  1.   

    关闭本页面并刷新父页面
    <script>
    if (window.opener != null)
    {
        window.opener.location.replace(window.opener.location);
    }
    window.opener=null;
    window.close();
    </script>
      

  2.   

    上面的代码是刷新页面,要是你的datagrid在第一次打开页面的时候自动绑定的话,就没问题也可以用
    window.opener.location.reload(true);
      

  3.   

    在你 B 窗口的插入按钮事件的最后,写下如下代码即可:private void Button1_Click(...)
    {
        //你的插入代码   //刷新父窗体,并关闭当前窗体;
       Response.Write("<Script language='JavaScript'>window.opener.location.href=window.opener.location.href;window.close();</Script>");
    }
      

  4.   

    如何点击按钮弹出新窗口,输入数据后返回并刷新页面?
    WebForm1.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
     Inherits="ShowModalDialog.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
      <HEAD>
      <title>WebForm1</title>
      <meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
      <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
      <meta content="JavaScript" name="vs_defaultClientScript">
      <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
       <div align="center">
       <form id="Form1" method="post" runat="server">
       <asp:label id="Label1" runat="server" Font-Bold="true">
        从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。
        </asp:label><br>
       <br>
       <asp:textbox id="TextBox1" runat="server" Width="600px">这是初始值,将被传递到新窗口。</asp:textbox><br>
       <br>
       <asp:button id="Button1" runat="server" Text="打开窗口" Width="96px"></asp:button></form>
      </div>
      </body>
    </HTML>WebForm1.aspx.vbPublic Class WebForm1
      Inherits System.Web.UI.Page
      Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
      Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
      Protected WithEvents Label1 As System.Web.UI.WebControls.Label
      Protected WithEvents Button1 As System.Web.UI.WebControls.Button#Region " Web 窗体设计器生成的代码 "  '该调用是 Web 窗体设计器所必需的。
      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
      End Sub#End Region  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If (Not IsClientScriptBlockRegistered("clientScript")) Then
          Dim strScript As String = "<script>" + vbCrLf
          strScript += "function OpenWin(){" + vbCrLf
          strScript += "var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value)" + vbCrLf
          strScript += "if(str!=null)  document.Form1.TextBox1.value=str" + vbCrLf
          strScript += "}" + vbCrLf
          strScript += "</script>" + vbCrLf
          RegisterClientScriptBlock("clientScript", strScript)
        End If
        Button1.Attributes.Add("onclick", "OpenWin()")
      End SubEnd ClassWebForm2.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="aspxWeb.mengxianhui.com.WebForm2"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
      <HEAD>
        <title>WebForm2</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <frameset rows="0,*">
        <frame src="about:blank">
        <frame src="WebForm3.aspx">
      </frameset>
    </HTML>WebForm2.aspx.vbPublic Class WebForm2
        Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 "  '该调用是 Web 窗体设计器所必需的。
      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
      End Sub#End Region  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
      End SubEnd ClassWebForm3.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb"
     Inherits="ShowModalDialog.WebForm3" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
      <HEAD>
       <title>WebForm3</title>
       <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
       <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
       <meta name="vs_defaultClientScript" content="JavaScript">
       <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout" id="MyBody" runat="server">
      <form id="Form1" method="post" runat="server">
       <asp:Label id="Label1" runat="server">请输入您的大名:</asp:Label><br>
       <br>
       <asp:TextBox id="TextBox1" runat="server" Width="558"></asp:TextBox><br>
       <br>
       <asp:Button id="Button1" runat="server" Text=" 提  交 "></asp:Button>
      </form>
      </body>
    </HTML>WebForm3.aspx.vbPublic Class WebForm3
      Inherits System.Web.UI.Page
      Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
      Protected WithEvents Label1 As System.Web.UI.WebControls.Label
      Protected WithEvents Button1 As System.Web.UI.WebControls.Button
      Protected MyBody As System.Web.UI.HtmlControls.HtmlControl#Region " Web 窗体设计器生成的代码 "  '该调用是 Web 窗体设计器所必需的。
      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
      End Sub#End Region  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If IsPostBack Then
          Dim strScript As String = "<script>" + vbCrLf
          strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "\'") + "'" + vbCrLf
          strScript += "window.parent.close()" + vbCrLf
          strScript += "</script>" + vbCrLf
          If (Not IsClientScriptBlockRegistered("clientScript")) Then
            RegisterClientScriptBlock("clientScript", strScript)
          End If
        End If
        If Not IsPostBack Then
          MyBody.Attributes.Add("onload", "document.Form1.TextBox1.value=window.parent.dialogArguments")
        End If
      End Sub
    End Class来自孟子