js处理的listBox列表后台取值
把你的listBox列表放到隐藏控件中,然后得到
js处理的listBox列表后台是不能直接得到的
方法<%@ Page Language="C#" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(HiddenField1.Value);
Response.Write("<br>");
Response.Write("你选中的是:" + Request.Form[ListBox1.UniqueID]);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var i = 1;
function SendTo() {
ls = document.getElementById("<%=ListBox1.ClientID %>");
st = []
sv = [];
for (i = 0; i < ls.options.length; i++) {
st.push(ls.options[i].text);
sv.push(ls.options[i].value);
}
document.getElementById("<%=HiddenField1.ClientID %>").value = st.join(",") + "|" + sv.join(",");
}
function Add() {
ls = document.getElementById("<%=ListBox1.ClientID %>");
ls.options[ls.options.length] = new Option("A" + i, "B" + i);
i++;
}
</script>
</head>
<body>
<form id="formd1" runat="server">
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>
<input type="button" value="添加" onclick="Add()" />
<asp:Button ID="Button1" runat="server" Text="传递" OnClick="Button1_Click" OnClientClick="SendTo();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</form>
</body>
</html>