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>

  • 相关阅读:
    JS中使用正则表达式封装的一些常用的格式验证的方法-是否外部url、是否小写、邮箱格式、是否字符、是否数组
    Java中操作字符串的工具类-判空、截取、格式化、转换驼峰、转集合和list、是否包含
    Cocos2d-x 2.0 自适应多种分辨率
    应用自定义移动设备外观
    为移动设备应用程序创建外观
    【2020-11-28】人生十三信条
    【2020-11-27】事实证明,逃避是下等策略
    Python 之web动态服务器
    Python 之pygame飞机游戏
    PHP 之转换excel表格中的经纬度
  • 原文地址:https://www.cnblogs.com/pchgo/p/1495863.html
Copyright © 2011-2022 走看看