1.aspx:<script>
        function GetMyValue(contrlname, myvalue) {            if (typeof (myvalue) == "undefined")
            { }
            else {
                document.getElementById(contrlname).value = myvalue;
            }
        }
  </script>
..............
<asp:TextBox ID="d_pname" runat="server" Width="129px"></asp:TextBox>
<input type="Button" id="ButtonDepAdd"   onclick="GetMyValue('d_pname',window.showModalDialog('SelectDeptForm.aspx'))" value="选择"  />
.........................
2、SelectDeptForm.aspx
...............
  <asp:TreeView ID="TreeView1" runat="server" Width="158px" >
                               <Nodes>
                                   <asp:TreeNode Text="技术公司" Value="技术公司" ImageUrl="~/images/node_dept.gif">
                                       <asp:TreeNode Text="技术开发" Value="技术开发"></asp:TreeNode>
                                       <asp:TreeNode Text="技术保证" Value="技术保证"></asp:TreeNode>
                                       <asp:TreeNode Text="客户服务" Value="客户服务"></asp:TreeNode>
                                   </asp:TreeNode>
                                   
                               </Nodes>
                </asp:TreeView>
__________________
想实现点击“TreeView1”后,把选择的TreeNode 的value值传递到1.aspx页面中的TextBox:d_pname中,并且关闭SelectDeptForm.aspx页面,如何实现,谢谢!

解决方案 »

  1.   

    注意: javascript: window.close(); 对服务器控件好像不行!
      

  2.   

    http://topic.csdn.net/u/20091112/09/342769c1-0abf-4f92-8699-7ac7d462e0cf.html
      

  3.   

    GetMyValue('d_pname'=>GetMyValue('<%= d_pname.ClientID%>'
      

  4.   

    看了,我试过,不行。我就想通过window.showModalDialog,调出子窗体(SelectDeptForm.aspx),在子窗体中选择输入文本框  TreeView 中选择某个节点后,关闭子窗体,并同时把选择的节点value返回给主窗体的 <asp:TextBox ID="d_pname" runat="server" Width="129px"></asp:TextBox>中。现在问题是
    1、子窗体不能关闭(可能是服务器控件);
    2、如何返回选择的节点值?
      

  5.   

    A.aspx<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
            window.onload = function() {            var button = document.getElementById('btn');            if (button) {                button.onclick = function() {                    var text = document.getElementById('<%=txtName.ClientID %>');                    window.showModalDialog('B.aspx', text);
                    }
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <input type='button' id='btn' value="请选择" />    
        </form>
    </body>
    </html>
    B.aspx<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <base target="_self" />
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:TreeView ID="tv" runat="server" 
            onselectednodechanged="tv_SelectedNodeChanged">       
        </asp:TreeView>
        </form>
    </body>
    </html>
    B.aspx.csprotected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tv.Nodes.Add(new TreeNode("小明", "1"));
                tv.Nodes.Add(new TreeNode("小刘", "2"));
                tv.Nodes.Add(new TreeNode("小张", "3"));
                tv.Nodes.Add(new TreeNode("小刚", "5"));
            }
        }
        protected void tv_SelectedNodeChanged(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(GetType(), "js", string.Format("window.dialogArguments.value='{0}';window.close();", tv.SelectedValue), true);
        }
      

  6.   

    在cs文件中实现treeview节点单击事件,内容如下:
     Response.Write("<script language:javascript>javascript:window.returnValue="+node的value+";</script>");
     Response.Write("<script language:javascript>javascript:window.close();</script>");在父页面中:
    var returnValue=window.showModalDialog(...);
    returnValue即所得。
      

  7.   


    还是不行!
    运行后不但不关闭,而且还多弹出一页。其地址是:javascript:__doPostBack('TreeView1','s1')
    内容里“无法显示该页”!
    到底是怎么回事啊
    谢谢
      

  8.   


    <base target="_self" />