关于子窗体传值给父窗体应该怎么传。我很菜。各位帮下忙!
我父窗体中点button的时候触发js的方法,把要传值控件的id传给子窗体        function newWindow(id)
        {
            
           window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
           
        }我子窗体中只有一个Textbox1和一个button1,我想在点button的时候把Textbox1的值传回给要传值的控件
应该怎么写,在后台和前台分别应该怎么写,各位用代码告诉我一下,在线等,全分送。谢谢!

解决方案 »

  1.   

    在js中,有一个方法是 windows.returnvalue=""
    这个东西 当你在父窗体单击button后 在子窗体写一个js
    windows.returnvalue=textbox1.text(假设具体取这个值,要看你的子窗体了)
    然后把父窗体的代码改为
    var testvalue=window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
    然后父窗体就可以得到子窗体的值了
    如果要传给其他页面。就要用到页面传值。或者上楼提到的session 也是可以的
      

  2.   

    parent.document.getElementById('父窗体控件id').value=this.Textbox1
      

  3.   

    WEB 里面没有子窗体 与 父窗体的概念。难道是框架 。parent.document.getElementById('父窗体控件id').value=this.Textbox1
    或者 
     window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");在 父页面 得到ID 的值用 SESSION 大材小用叻
      

  4.   

    错。WEB里面有子窗体 与 父窗体的概念。 LZ表受误导
      

  5.   

    对,web中确实存在父窗体子窗体的概念。顶!
      

  6.   

    parent.document.getElementById('父窗体控件id').value=this.Textbox1 
    学到一点~
      

  7.   

    codeparent.document.getElementById('父窗体控件id').value=this.Textbox1 
      

  8.   

    在button的click事件中写如下代码 StringBuilder sb = new StringBuilder();//引入using System.Text命名
     sb.Append("window.parent.opener.document.getElementById('父窗体控件的id').value='" Textbox1.Text + "';window.close();");
     Type t = this.GetType();
     ClientScriptManager cs = Page.ClientScript;
     cs.RegisterStartupScript(t, "", sb.ToString(), true);
      

  9.   

    前臺寫法:
    父窗體:
    var arr =window.showModalDialog('../TestAjax/slectZRren.aspx?type='+type,'請選擇責任人','dialogWidth:500px;dialogHeight:500px;status:no;help:no');
    if (arr!= null)
                {
                    var ss;
                    document.getElementById(txtFZRen).value = ss[0];
                }
    子窗體:
    var lab2 = document.getElementById("TextBox1");
    window.returnValue = lab2;
    window.close();
      

  10.   

    直接在字窗口中button1的onclick事件中执行
    opener.document.getElementById('父窗口接受参数控件的id').value=document.getElementById('TextBox1');opener指向父窗口
      

  11.   

    1)子窗口給父窗口中的控件賦值,以達到傳回子窗体的值:
    父窗体:
     function newWindow(id)
        {
           window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
        }
    子窗体:function Return()
        {
            window.parent.opener.document.getElementById('<%=TextBox1.ClientID %>').value=document.getElementById('<%=TextBox1.ClientID %>').value ;
            window.close();
        }
    this.Button2.Attributes.Add("onclick", "Return()");
    2)通過子窗体傳回值給父窗体
    父窗体:
     function newWindow(id)
        {
           var strReturn=window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
        }
    子窗体:
    function Return()
        {
            windows.returnvalue = document.getElementById('<%=TextBox1.ClientID %>').value ;
            window.close();
        }
      

  12.   

    父窗口js:
    function newWindow(id)
    {      
       var strReturn=window.showModalDialog("ceshi.aspx?id="+id+","sub","dialogTop:200px;dialogLeft:300px");
       document.getElementById('父窗体控件id').value=strReturn;  
    }ceshi.aspx页面(子窗口)
    在<head>后最好添加一个<base target="_self" />
    js代码:
    function setstr()
    {
        var strResult=document.getElementById("Textbox1").value;
        window.returnValue=strResult;
        window.close();
    }cs:
        protected void ImageButton2_Click(object sender, EventArgs e)
        {
            string str = "<script type='text/javascript'>setstr();</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "1", str);
            
        }
      

  13.   

    看来对JS熟悉的人还真不多,我就看到一个是正确答案。
    用opener
    如:17楼。
      

  14.   

    widow.opener.documentByID("ID").value=window.documentByID("本页面控件ID").value
      

  15.   

    参考:http://download.csdn.net/source/393738
      

  16.   

    上传时,有提示成功上传,但是别人下载不了.
    看来是白做,白写和白录影片!
    另外,csdn上传出了问题,几次向csdn问题反映,都没有人理,也没有回音!
      

  17.   

    现在可以下载了:http://download.csdn.net/source/393738