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页面,如何实现,谢谢!
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、子窗体不能关闭(可能是服务器控件);
2、如何返回选择的节点值?
<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);
}
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即所得。
还是不行!
运行后不但不关闭,而且还多弹出一页。其地址是:javascript:__doPostBack('TreeView1','s1')
内容里“无法显示该页”!
到底是怎么回事啊
谢谢
<base target="_self" />