ASP.NET 2.0 中实现跨页提交:一般都是两个页面相互切换是实现的!
我现在在一个页面(旧)中有个按钮,单击后出现一个比较小的页面(新),这是页面(旧)就在页面(新)的下方还能看到!!页面(新)中一个按钮,单击后把页面(新)关掉,并把一个string的值传到页面(旧)的 TextBox中,如何实现?
请各位指教,谢谢,非常感谢!!

解决方案 »

  1.   

    传值:
    1、可以通过Session
    2、在旧页面中定义一个静态static的string变量
    来实现
      

  2.   

    Session或viewstate都可以,不要用静态变量
      

  3.   

    做网页最好不要用静态变量,多人在线会出现问题的。用Session或viewstate。
      

  4.   

    问题是 页面(新)中一个按钮,单击后把页面(新)关掉 时,页面(旧)中如何促发时间来把string的值放到 TextBox中
      

  5.   

    问题是 页面(新)中一个按钮,单击后把页面(新)关掉 时,页面(旧)中如何促发事件来把string的值放到 TextBox中
      

  6.   

    用JAVASCRIPT弹出模式对话框
    里面可以写返回值(旧)var yourstring = window.showModalDialog(......)
    (新)window.returnValue = yourstring
      

  7.   

    1. Session 或 Static 变量2. 脚本也可以实现
      

  8.   

    传入参数: 
    要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如: test1.htm 
    ==================== 
    <script> 
      var mxh1 = new Array("mxh","net_lover","孟子E章") 
      var mxh2 = window.open("about:blank","window_mxh") 
      // 向对话框传递数组 
      window.showModalDialog("test2.htm",mxh1) 
      // 向对话框传递window对象 
      window.showModalDialog("test3.htm",mxh2) 
    </script> test2.htm 
    ==================== 
    <script> 
      var a = window.dialogArguments 
      alert("您传递的参数为:" + a) 
    </script> test3.htm 
    ==================== 
    <script> 
      var a = window.dialogArguments 
      alert("您传递的参数为window对象,名称:" + a.name) 
    </script> 可以通过window.returnvalue向打开对话框的窗口返回信息,当然也可以是对象。例如: test4.htm 
    =================== 
    <script> 
      var a = window.showModalDialog("test5.htm") 
      for(i=0;i<a.length;i++) alert(a[i]) 
    </script> test5.htm 
    =================== 
    <script> 
    function sendTo() 

      var a=new Array("a","b") 
      window.returnvalue = a 
      window.close() 

    </script> 
    <body> 
    <form> 
      <input value="返回" type=button onclick="sendTo()"> 
    </form>
      

  9.   

    非常感谢 jc15271149 !!
    window.returnvalue 返回值时,可以得到服务器控件TextBox.Text吗?
    返回的值是不是只是客户端能看都,服务器控件根本不知道它的值已经改变了?
      

  10.   

    default.aspx
    <%@ 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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
    <input id="Text1" type="text" />
    <input id="Button1" type="button" value="button" onclick="window.open('a.aspx', '_blank', 'width=400,height=300')" />
        </form>
    </body>
    </html>a.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %><!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>Untitled Page</title>
        <script type="text/javascript">
    function btn_click() {
    window.opener.document.getElementById('Text1').value = document.getElementById('param').value;
    window.close();
    }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
    <input type="text" id="param" /><input type="button" value="Close" onclick="btn_click();"
        </form>
    </body>
    </html>
      

  11.   

    要是服务器控件的话用这个
    document.getElementById("<%= TextBox1.ClientID %>");
      

  12.   

    非常感谢 avisnet !!
    你举的例子可以用,谢谢!
    但是,我的都是服务器控件,用document.getElementById("<%= TextBox1.ClientID %>")提示:当前上下文中不存在TextBox1!
      

  13.   

    厄~
    有时候提问问题者请自行理解某些问题~
    如果连基本功都没掌握,即使别人给出了该怎么做的方案,提问者还是不懂就是个人修为的问题了~
    document.getElementById("<%= TextBox1.ClientID %>")
    这个是使用了嵌入式代码块 (Embedded Code Blocks)
    Embedded Code Blocks
    帮助是这么写di:
     嵌入式代码块中,语法 <% = expression %> 用于解析表达式,并将其值返回到块中。 
    下面的代码示例演示一个嵌入式代码块,该代码块显示 span 元素中的公共 GetTime() 函数的值。在嵌入式代码块中,语法 <% = expression %> 用于解析表达式,并将其值返回到块中。
    <%@ Page Language="C#" %>
    <script runat=server>
    protected String GetTime()
    {
        return DateTime.Now.ToString("t");
    }
    </script>
    <html>
    <body>
        <form id="form1" runat="server">
           Current server time is <% =GetTime()%>.
        </form>
    </body>
    </html>
      

  14.   

    不要意思,刚才发错了!!
    是window.opener.document.getElementById("<%= Text1.ClientID %>")提示:当前上下文中不存在TextBox1!
    因为default.aspx中我用的是服务器控件 TextBox!
    谢谢!!
      

  15.   

    那就用TextBox1啊,TextBox1就是服务器控件的ID
      

  16.   

    <%@ 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>Untitled Page</title>
        <script type="text/javascript">
    window.onload = function() {
    document.getElementById("<%= TextBox1.ClientID %>").value = "wjs";
    }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </form>
    </body>
    </html>
      

  17.   

    页面:D.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="D.aspx.cs" Inherits="D" %>
    <!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 id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
    <input id="Button1" type="button" value="button" onclick="window.open('a.aspx', '_blank', 'width=400,height=300')" />
            <br />
            <asp:TextBox ID="txtBox1" runat="server"></asp:TextBox>
        </form>
    </body>
    </html>页面:a.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %><!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 id="Head1" runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
    function btn_click() {
    window.opener.document.getElementById("<%= txtBox1.ClientID %>").value = document.getElementById("<%= TextBox1.ClientID %>").value;
    window.close();
    }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <input type="button" value="Close" onclick="btn_click();" />
        </form>
    </body>
    </html>
    提示:当前上下文中不存在txtBox1!
      

  18.   

    看了楼主的代码,晕啊~建议掌握了javascript的基础知识再来问这个问题
    window.opener.document.getElementById("<%= txtBox1.ClientID %>").
    厄~,<%是嵌入块,只能使用当前页面的服务器控件,而window.opener是指当前页的打开者,即是你点了按钮打开了当前页面的那个页面,厄~,楼主的水平未免太菜了~
      

  19.   

    用客户端脚本和DHTML很容易实现的事情,如果想用回发机制,将困难得几乎无法完成,如果开发Web对客户端脚本和DHTML没有任何了解仅仅依赖于拖拽控件的话,是不可能开发出什么好东西出来的。
      

  20.   

    (旧)var yourstring = window.showModalDialog(......)
      

  21.   

    谢谢所有各位!
    在页面(旧)中<input type="text" id="param" runat="server"/>就可以了,非常感谢!