• window.showModalDialog()弹出窗口获取返回值


    可以返回值的弹出窗口:用的是window.showModalDialog()方法. window.showModalDialog(URL,dialogArgments.features) 打开一个新窗口

    当弹出窗口关闭的时候就能得到返回值,下面有个简单的例子:

    开发环境: Visual Studio.Net 2003(C#) + IE6.0

    A.aspx
    Java代码 复制代码
    1. <SCRIPT LANGUAGE=JAVASCRIPT>   
    2.     function btnGetReturnValue_onclick()    
    3.     {   
    4.                   var temp= window.showModalDialog("B.aspx","","center=yes;help=no;status=no");    
    5.                   document.Form1.TextBox1.value = temp;   
    6.     }   
    7. </SCRIPT>   
    8. .......   
    9. <Input  Type="Button" id=" btnGetReturnValue" onclick="return btnGetReturnValue_onclick() value="获取">  
    <SCRIPT LANGUAGE=JAVASCRIPT>    function btnGetReturnValue_onclick()     {                  var temp= window.showModalDialog("B.aspx","","center=yes;help=no;status=no");                  document.Form1.TextBox1.value = temp;    }</SCRIPT>.......<Input  Type="Button" id=" btnGetReturnValue" onclick="return btnGetReturnValue_onclick() value="获取">

    B.aspx.cs
    Java代码 复制代码
    1. 在你想操作的事件中加上   
    2. string str = "返回值"  
    3. Response.Write("<script language=javascript>window.returnValue ="+str+";window.close()</script>");  
    在你想操作的事件中加上string str = "返回值"Response.Write("<script language=javascript>window.returnValue ="+str+";window.close()</script>");

    我的测试:
    test.aspx
    Java代码 复制代码
    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>   
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    4.  <HTML>      
    5.   <HEAD>      
    6.   <TITLE></TITLE>      
    7.   
    8.   </HEAD>      
    9.   <BODY>      
    10.   <form id="Form1" method="post" runat="server">   
    11.   <SCRIPT LANGUAGE=JAVASCRIPT>   
    12.     function btnGetReturnValue_onclick()    
    13.     {   
    14.                   var temp= window.showModalDialog("testopen.aspx","","center=yes;help=no;status=no");   
    15.                       if   (temp!=undefined)      
    16.                           {      
    17.                             document.Form1.TextBox1.value = temp;   
    18.                           }      
    19.                         else  
    20.                         {   
    21.                             document.Form1.TextBox1.value = "null";    
    22.                         }   
    23.   
    24.     }   
    25. </SCRIPT>   
    26. <Input  Type="Button" id=" btnGetReturnValue" onclick="return btnGetReturnValue_onclick()" value="获取">   
    27.          
    28.       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>   
    29. </form>   
    30.   </BODY>      
    31.   </HTML>   
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML>     <HEAD>     <TITLE></TITLE>     </HEAD>     <BODY>     <form id="Form1" method="post" runat="server">  <SCRIPT LANGUAGE=JAVASCRIPT>    function btnGetReturnValue_onclick()     {                  var temp= window.showModalDialog("testopen.aspx","","center=yes;help=no;status=no");                      if   (temp!=undefined)                             {                               document.Form1.TextBox1.value = temp;                          }                           else                        {                            document.Form1.TextBox1.value = "null";                         }    }</SCRIPT><Input  Type="Button" id=" btnGetReturnValue" onclick="return btnGetReturnValue_onclick()" value="获取">            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></form>  </BODY>     </HTML> 

    testopen.aspx
    Java代码 复制代码
    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="testopen.aspx.cs" Inherits="testopen" %>   
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    4.   
    5. <HTML>      
    6.   <HEAD>      
    7.   <TITLE></TITLE>      
    8.   
    9.   </HEAD>      
    10.      
    11.   <BODY>      
    12.   <base target="_self">   
    13. <form id="Form1" method="post" runat="server">   
    14.     <asp:TextBox ID="cc" runat="server"></asp:TextBox>   
    15.     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />   
    16.   
    17. </form>   
    18.   </BODY>      
    19.   </HTML>  
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="testopen.aspx.cs" Inherits="testopen" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML>     <HEAD>     <TITLE></TITLE>     </HEAD>       <BODY>     <base target="_self"><form id="Form1" method="post" runat="server">    <asp:TextBox ID="cc" runat="server"></asp:TextBox>    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></form>  </BODY>     </HTML>

    testopen.aspx.cs
    Java代码 复制代码
    1. using System;   
    2. using System.Data;   
    3. using System.Configuration;   
    4. using System.Collections;   
    5. using System.Web;   
    6. using System.Web.Security;   
    7. using System.Web.UI;   
    8. using System.Web.UI.WebControls;   
    9. using System.Web.UI.WebControls.WebParts;   
    10. using System.Web.UI.HtmlControls;   
    11.   
    12. public partial class testopen : System.Web.UI.Page   
    13. {   
    14.     protected void Page_Load(object sender, EventArgs e)   
    15.     {   
    16.     }   
    17.     protected void Button1_Click(object sender, EventArgs e)   
    18.     {   
    19.         string str = this.cc.Text.ToString();   
    20.         Response.Write(str);   
    21.         Response.Write("<script language=javascript>window.parent.returnValue ='" + str + "';window.parent.close();</script>");//   
    22.     }   
    23. }  
  • 相关阅读:
    Alice and Bob(博弈)
    Cuckoo for Hashing(hash)hunnuoj
    Median(vector+二分)
    Open Credit System(UVA11078)
    First Date (hnoj12952)日期计算
    Inviting Friends(hdu3244 && zoj3187)完全背包+二分
    Factorial Problem in Base K(zoj3621)
    吉哥系列故事——临时工计划(dp)
    密码是我的QQ号
    Beans Game(博弈 | | DP)zoj 3057
  • 原文地址:https://www.cnblogs.com/queen/p/1789845.html
Copyright © 2020-2023  润新知