我用了js 就是传值的话只有listbox的value能传过去 对应的text是怎么传得, 而且传过去的值在textbox中不能显示父页面: function studyShowModalDialog() { var m = window.showModalDialog("SelectStas.aspx?temp=" + Math.random(),"", "dialogHeight:300px,center:yes,resizable:yes,status:no"); if (m != null) { alert(m); window.document.getElementById("MuliSignT").value = m; } window.location.reload();
}子页面: function GetDataAndClose() { var objList = document.getElementById("lbStaffRight"); var str = " "; var strs = ""; for(var i=0;i <objList.options.length;i++){ str = str + objList.options[i].value;
} window.returnValue = str; window.close(); }
方法很多,下面是一个完整的例子。你只需拷贝转贴进行进行测试即可 test.aspx<%@ Page Language="C#" %><!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></title> <script type="text/javascript"> function add(t, v) { ls = document.getElementById("ListBox1"); st = t.split(",") sv = v.split(",") ls.options.length = 0; for (i = 0; i < st.length; i++) { ls.options[ls.options.length] = new Option(st[i], sv[i]); } } </script> </head> <body> <form id="form1" runat="server"> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="window.showModalDialog('b.aspx',window);return false" /> </form> </body> </html> B.aspx <%@ Page Language="C#" %><!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></title> <script type="text/javascript"> function SendTo() { ls = document.getElementById("ListBox1"); st = [] sv = []; for (i = 0; i < ls.options.length; i++) { st.push(ls.options[i].text); sv.push(ls.options[i].value); } window.dialogArguments.add(st.join(","), sv.join(",")) window.close(); } </script> </head> <body> <form id="form1" runat="server">
就是传值的话只有listbox的value能传过去 对应的text是怎么传得,
而且传过去的值在textbox中不能显示父页面: function studyShowModalDialog() {
var m = window.showModalDialog("SelectStas.aspx?temp=" + Math.random(),"", "dialogHeight:300px,center:yes,resizable:yes,status:no"); if (m != null) {
alert(m);
window.document.getElementById("MuliSignT").value = m; } window.location.reload();
}子页面: function GetDataAndClose() {
var objList = document.getElementById("lbStaffRight");
var str = " ";
var strs = "";
for(var i=0;i <objList.options.length;i++){
str = str + objList.options[i].value;
}
window.returnValue = str;
window.close(); }
test.aspx<%@ Page Language="C#" %><!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></title>
<script type="text/javascript">
function add(t, v) {
ls = document.getElementById("ListBox1");
st = t.split(",")
sv = v.split(",")
ls.options.length = 0;
for (i = 0; i < st.length; i++) {
ls.options[ls.options.length] = new Option(st[i], sv[i]);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="window.showModalDialog('b.aspx',window);return false" />
</form>
</body>
</html>
B.aspx
<%@ Page Language="C#" %><!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></title>
<script type="text/javascript">
function SendTo() {
ls = document.getElementById("ListBox1");
st = []
sv = [];
for (i = 0; i < ls.options.length; i++) {
st.push(ls.options[i].text);
sv.push(ls.options[i].value);
}
window.dialogArguments.add(st.join(","), sv.join(","))
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="传递" OnClientClick="SendTo();return false" />
</form>
</body>
</html>
就是text内容
if (tvCorp.SelectedNode.Value.Length > 1)
{
string pk = tvCorp.SelectedNode.Value;
string name = tvCorp.SelectedNode.Text;
string ary = pk + ":" + name;
Response.Write("<script language=javascript>");
Response.Write("window.returnValue='" + ary.ToString() + "';");
Response.Write("window.close();");
Response.Write("</script>");
}
else
{
Frame.Window w = new Window();
w.Alert("不能选择此部门!", this);
}主页面:
//传递两个TB控件名,Corp公司PK,Dept部门
function JSPerson_TB_getAllDept(tb1,tb2)
{
var result;
result = window.showModalDialog("/Bussiness/UC/GetAllDept.aspx?Corp="+Corp+"&Dept=1",'','dialogHeight:600px; dialogWidth:330px; center: yes; help: no;status:no');
if (result != 'undefined' && typeof(result)!='undefined')
{
var rv = result.split(":");
if (rv.length == 2);
{
document.getElementById(tb1).value =rv[0];
document.getElementById(tb2).value =rv[1];
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function add() {
a = window.showModalDialog('b.aspx')
t = a.split("|")[0];
v = a.split("|")[1];
ls = document.getElementById("ListBox1");
st = t.split(",")
sv = v.split(",")
ls.options.length = 0;
for (i = 0; i < st.length; i++) {
ls.options[ls.options.length] = new Option(st[i], sv[i]);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="add();return false;" />
</form>
</body>
</html>
b.aspx
<%@ Page Language="C#" %><!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></title>
<script type="text/javascript">
function SendTo() {
ls = document.getElementById("ListBox1");
st = []
sv = [];
for (i = 0; i < ls.options.length; i++) {
st.push(ls.options[i].text);
sv.push(ls.options[i].value);
}
window.returnValue = st.join(",") + "|" + sv.join(",");
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="传递" OnClientClick="SendTo();return false" />
</form>
</body>
</html>
add(t, v)是在哪被调用的
在b.aspx里面啊
window.dialogArguments.add(st.join(","), sv.join(","))这是第一种方法里面的使用方法
调试的时候显示ls.options.length = 0; 运行错误 缺少对象
主页面: <script type="text/javascript" language="javascript"> function add() {
a = window.showModalDialog("SelectStas.aspx?temp=" + Math.random(), "", "dialogHeight:300px,center:yes,resizable:yes,status:no")
t = a.split("|")[0];
v = a.split("|")[1];
ls = document.getElementById("GetData");
st = t.split(",")
sv = v.split(",")
ls.options.length = 0;
for (i = 0; i < st.length; i++) {
ls.options[ls.options.length] = new Option(st[i], sv[i]);
}
}
<asp:listbox id="GetData" runat="server" Rows="10" SelectionMode="Multiple" Width="200"></asp:listbox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="add()();return false;" />
</script> 子页面: function SendTo() {
ls = document.getElementById("lbStaffRight");
st = []
sv = [];
for (i = 0; i < ls.options.length; i++) {
st.push(ls.options[i].text);
sv.push(ls.options[i].value);
}
window.returnValue = st.join(",") + "|" + sv.join(",");
window.close();
} <asp:Button ID="Button1" runat="server" Text="传递" OnClientClick="SendTo();return false" />
就是显示那个缺少对象
<asp:ListBox Id="lbStaffRight" 吗?
就是getdata这个listbox不显示值
<asp:listbox id="GetData" runat="server" Rows="10" SelectionMode="Multiple" Width="200"></asp:listbox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="add()();return false;" />
</script> 你的代码放在</script> 里面? OnClientClick="add()();return false;"有这样调用函数的吗?
拷贝我的例子直接进行测试,就知道是否有错误了,
如果我的例子有错,那是我的问题,如果我的例子没错,你的代码出错,那你应该去对照你自己的代码哪里出问题了。
为什么this.listbox1.items.count取不到值啊
为什么this.listbox1.items.count取不到值啊
js和ajax添加的选项,是不能使用this.listbox1.items.count进行获取的。
只能在客户端进行获取。包括listbox1.SelectedValue等都是不能使用的,
你需要使用
Request.Form["listbox1"]得到选中的要得到this.listbox1.items.count,你需要在客户端计算传到服务器端
比如主页面的后台要使用子页面的listbox。value