zoukankan      html  css  js  c++  java
  • 点击按钮弹出新窗口,输入数据后返回并刷新页面(C#代码) 窗口互传值(转)

    Webform1.aspx

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

    <!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>
      <title>WebForm1</title>
      
     </head>
     <body >
      <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" Width="96px" Text="打开窗口2"></asp:button>
        <asp:button id="Button2" runat="server" Width="96px" Text="打开窗口4"></asp:button></form>
      </div>
     </body>
    </HTML>


    Webform1.aspx.cs

    public partial class pchgoTest_Webform1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetScript();
        }

        protected void GetScript()
        {
            // 在此处放置用户代码以初始化页面
            string strScript = "\n";
            if (!IsClientScriptBlockRegistered("clientScript"))
            {
                strScript = "<script>\n";
                strScript += "function OpenWin(){\n";
                strScript += "var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value,'help:no')\n";
                strScript += "if(str!=null)  document.Form1.TextBox1.value=str\n";
                strScript += "}\n";
                strScript += "</script>\n";
                RegisterClientScriptBlock("clientScript", strScript);
            }
            if (!IsClientScriptBlockRegistered("clientScript2"))
            {
                strScript = "<script>\n";
                strScript += "function OpenWin2(){\n";
                strScript += "var str=window.showModalDialog('WebForm4.aspx',document.Form1.TextBox1.value,'help:no')\n";
                strScript += "if(str!=null)  document.Form1.TextBox1.value=str\n";
                strScript += "}\n";
                strScript += "</script>\n";
                RegisterClientScriptBlock("clientScript2", strScript);
            }
            Button1.Attributes.Add("onclick", "OpenWin()");
            Button2.Attributes.Add("onclick", "OpenWin2()");

        }
    }

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;



    Webform2.aspx

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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>WebForm2</title>
     </head>
    <frameset rows="0,*">
      <frame src="about:blank">
      <frame src="WebForm3.aspx">
     </frameset>
    </html>


    WebForm3.aspx

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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>WebForm3</title>
    </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="320px"></asp:TextBox><br>
            <br>
            <asp:Button ID="Button1" runat="server" Text=" 提  交 "></asp:Button>
        </form>
    </body>
    </html>


    WebForm3.aspx.cs

     using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class pchgoTest_WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string strScript = "<script>\n";
                strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "\'") + "'\n";
                strScript += "window.parent.close()\n";
                strScript += "</script>\n";
                if (!IsClientScriptBlockRegistered("clientScript"))
                    RegisterClientScriptBlock("clientScript", strScript);
            }
            else
            {
                MyBody.Attributes.Add("onload", "document.Form1.TextBox1.value=window.parent.dialogArguments");
            }

        }
    }

    Webform4.aspx

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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>WebForm4</title>
    </head>
    <body ms_positioning="GridLayout">
        <form id="Form1" method="post" runat="server">
            <iframe frameborder="no" src='WebForm3.aspx' style=" 368px; height: 192px"></iframe>
        </form>
    </body>
    </html>

  • 相关阅读:
    C# Asp.net 获取上上次请求的url
    Asp.net 中 Get和Post 的用法
    慎用JavaScript:void(0)
    JS验证RadioButton列表或CheckBox列表是否已填写
    .net 中viewstate的原理和使用
    Javascript与C#互相调用
    获取当前页面URL并UTF8编码之
    C#信息采集工具实现
    C#泛型编程
    C#正则表达式提取HTML中IMG标签的URL地址 .
  • 原文地址:https://www.cnblogs.com/pchgo/p/1495863.html
Copyright © 2011-2022 走看看