我正在尝试使用下面的代码将列表中的项目存储到会话中。出于某种原因,当我调试代码时,即使列表框中有多个项目,计数也会返回 0?有什么想法我在这里做错了吗?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NameTextBox_AutoCompleteExtender.OnClientItemSelected = "getSelected"
End Sub
Protected Sub cmdNext_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles cmdNext.Click
Dim n As Integer = NPListbox.Items.Count
Dim arr As String() = New String(n - 1) {}
For i As Integer = 0 To arr.Length - 1
arr(i) = NPListbox.Items(i).ToString()
Next
Session("arr") = arr
Response.Redirect("~/frmDescription.aspx")
End Sub
<script language="javascript" type="text/javascript">
function getSelected(source, eventArgs) {
var s = $get("<%=NameTextBox.ClientID %>").value;
var opt = document.createElement("option");
opt.text = s.substring(s.length - 10);
opt.value = s.substring(s.length - 10);
document.getElementById('<%= NPListbox.ClientID %>').options.add(opt);
}