比如你的子窗口用window.showModalDialog(.......) 打开你在子窗口里定义 window.top.returnValue = ***;(***是你要传的值)在父窗口里定义一个变量接收就可以了 var val = window.showModalDialog(.....)不知道这样说你明白 呵呵:)

解决方案 »

  1.   

    弹出窗体给父窗体的控件赋值的一个例子 
    1.弹出窗口html<%@ Page language=c# Codebehind=Web_Dialog_Customer.aspx.cs AutoEventWireup=false Inherits=PI.Web_Dialog_Customer %>
    <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN >
    <HTML>
     <HEAD>
      <title>Web_Dialog_Customer</title>
      <META http-equiv=”Pragma” content=”no-cache”>
      <META http-equiv=”Cache-Control” content=”no-cache”>
      <meta content=Microsoft Visual Studio .NET 7.1 name=GENERATOR>
      <meta content=C# name=CODE_LANGUAGE>
      <meta content=JavaScript name=vs_defaultClientScript>
      <meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
      <base target=_self>
     </HEAD>
     <body bgColor=#f2f2f1 MS_POSITIONING=GridLayout>
      <form id=Form1 method=post runat=server>
       <FONT face=宋体>
        <asp:datagrid id=DataGrid1 style=Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px runat=server
         Height=168px CellPadding=1 BorderColor=Black BorderWidth=1px Font-Size=9pt Font-Names=宋体
         ShowFooter=True AutoGenerateColumns=False Width=248px>
         <HeaderStyle HorizontalAlign=Center Height=30px ForeColor=Black VerticalAlign=Middle
          BackColor=WhiteSmoke></HeaderStyle>
         <Columns>
          <asp:BoundColumn Visible=False DataField=cust_no ReadOnly=True HeaderText=客户代码></asp:BoundColumn>
          <asp:TemplateColumn HeaderText=客户名称>
           <ItemTemplate>
            <asp:TextBox id=txt_cust_name runat=server Width=240px Height=24px Text='<%# DataBinder.Eval(Container, DataItem.cust_name) %>'>
            </asp:TextBox>
           </ItemTemplate>
          </asp:TemplateColumn>
         </Columns>
        </asp:datagrid></FONT></form>
     </body>
    </HTML>
    弹出窗口cs
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace PI
    {
     /// <summary>
     /// Web_Dialog_Customer 的摘要说明。
     /// </summary>
     public class Web_Dialog_Customer : System.Web.UI.Page
     {
      protected System.Web.UI.WebControls.DataGrid DataGrid1;
     BLL.b_Dialog_Customer bdc=new BLL.b_Dialog_Customer(); 
      private void Page_Load(object sender, System.EventArgs e)
      {
       // 在此处放置用户代码以初始化页面
       if(!Page.IsPostBack)
       {
        this.DataGrid1.DataSource=bdc.c_Dialog_Customer(Page.Request.QueryString[sales],Page.Request.QueryString[desc] );
        this.DataGrid1.DataBind();
       }  }  #region Web 窗体设计器生成的代码
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {    
       this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
       this.Load += new System.EventHandler(this.Page_Load);  }
      #endregion  private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
       if(e.Item.ItemType==ListItemType.AlternatingItem | e.Item.ItemType==ListItemType.Item)
       {
        TextBox t_cust_name=(TextBox) e.Item.FindControl(txt_cust_name);  
        t_cust_name.Attributes.Add(onkeydown, if(event.keyCode==13) {var a=new Array( + e.Item.Cells[0].Text+ , +t_cust_name.ClientID+ .value ); window.opener=null;window.returnValue =a;window.close()});
       }
      }
     }
    }父窗口cs
        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {    js=if(event.keyCode==13) ;
        js+= {var desc= + dc.c_Chinese_CUST_NAME.ClientID + .value;;
        js+=var sales='+ user+';;
        js+=var nDialogWidth=700;var nDialogHeight=400;;
        js+=var nLeft=(window.screen.availWidth-nDialogWidth)/2;;
        js+=var nTop=(window.screen.availHeight-nDialogHeight)/2;;
        js+=var sFeatures='dialogLeft:'+nLeft+'px;dialogTop:'+nTop+'px;dialogHeight:'+nDialogHeight+'px;dialogWidth:'+nDialogWidth+'px;help:no;status:no';;
        js+=var bLogged=window.showModalDialog('Web_Dialog_Customer.aspx?type=1&desc='+escape(desc)+'&sales='+escape(sales),window,sFeatures);;
        js+=if(bLogged != null);
        js+=    { + dc.c_Chinese_CUST_NAME.ClientID + .value=bLogged[1];;
        js+=        dc.cust_no.ClientID+.value=bLogged[0];;
        js+=    };
        js+=};event.keyCode=9;;   
        dc.c_Chinese_CUST_NAME.Attributes.Add(onkeydown,js);
    }
    2.function  GetText()  
    {  
    var objtxt = document.getElementById(Text_Uper);                             
    opener.document.Form1.textBox_Uper.value=objtxt.value;  
    }  
      

  2.   

    哪里用到我的代码了? 你说的是梅花雪老大,不是一个人啊~不知道你有什么不明白,都说一下好了要处理树的单击事件或者双击事件只要改下js就可以了对应的函数是:clickHandle和DblclickHandle.在这两个方法的后面添加你自己的处理方法.文本框在document里有一个唯一的sourceIndex,你可以在打开窗口的时候把这个值传到子窗口里,点击事件中可以用window.opener.document.all(sourceIndex)来得到打开窗口的控件.当然,方法还有别的,还可以用模态窗口打开,把对象作为参数传过去也行.另外说一点,每次点击都查次数据库是不是不太好,可以把数据一次取出放到你窗口里,显示树的时候都用这些数据(只适合数据相对较少改变的情况)
      

  3.   

    to zhaoxiaoyang(梅雪香@深圳) :对不起,我搞错了。不过我现在发现了姓梅的好像都很厉害,我在想我是不是也该改改名了,还有我的数据很多的,可能要有几千条的,还有那个sourceIndex是唯一的吗?即使文本框的名字一样,它也不一样吗?那我是不是在子窗口里把值赋给window.opener.document.all(sourceIndex)就行了呢?还有我在主窗口里怎么获取那个sourceIndex?to njtucomputer(冬虫草):因为我在主窗口上的文本框是循环显示的。