I'm trying to add a JavaScript function to show all selected items from a ListBox as concatentated strings in a Label on the page. It's needed because AutoPostBack="true" will cause the ListBox to scroll all the way back to the first selected item.
So this code works:
<script type="text/javascript">
function Updatelist() {
var sel = document.getElementById('<%=lstbxStuff.ClientID%>');
var lbl = document.getElementById('ctl00_cph_lblSelectedStuff');
var listLength = sel.options.length;
var textForListbox = "";
var list2length = 0;
for (var i = 0; i < listLength; i++) {
if (sel.options[i].selected) {
if(list2length == 0) {
textForListbox = sel.options[i].text;
} else {
textForListbox = textForListbox + ", " + sel.options[i].text;
}
list2length++;
}
}
lbl.innerText=textForListbox;
return textForListbox;
}
</script>
Unfortunately I still need the code behind SelectedIndexChanged delegate. Is there a way to use both of these without doing a PostBack? When I set AutoPostBack="false", my delegate never seems to be reached.