I have a javascript function below to move from select multiple box A which is populated from database to another multiple select box B, in the event of a postback my values in B which are moved over from A got lost. Initially I thought because I included a “runat=”server”” tag for server side actions but apparently it’s not the case. I read about Form.Request but ain’t have a clue how to go about it. I just need to retain those values in multiple select box B. Please kindly advice. Thanks.
<%– Move items to and fro select box –%>
function move(sourceFrom, sourceTo) {
var arrFrom = new Array();
var arrTo = new Array();
var arrLU = new Array();
var i;
for (i = 0; i < sourceTo.options.length; i++) {
arrLU[sourceTo.options[i].text] = sourceTo.options[i].value;
arrTo[i] = sourceTo.options[i].text;
}
var fLength = 0;
var tLength = arrTo.length;
for (i = 0; i < sourceFrom.options.length; i++) {
arrLU[sourceFrom.options[i].text] = sourceFrom.options[i].value;
if (sourceFrom.options[i].selected && sourceFrom.options[i].value != "") {
arrTo[tLength] = sourceFrom.options[i].text;
tLength++;
} else {
arrFrom[fLength] = sourceFrom.options[i].text;
fLength++;
}
}
sourceFrom.length = 0;
sourceTo.length = 0;
var ii;
for (ii = 0; ii < arrFrom.length; ii++) {
var no = new Option();
no.value = arrLU[arrFrom[ii]];
no.text = arrFrom[ii];
sourceFrom[ii] = no;
}
for (ii = 0; ii < arrTo.length; ii++) {
var no = new Option();
no.value = arrLU[arrTo[ii]];
no.text = arrTo[ii];
sourceTo[ii] = no;
}
(sourceTo).focus();
if (sourceTo == (document.getElementById('<%= outletFromBox.ClientID%>'))) {
(sourceFrom).focus();
}
if (sourceTo == (document.getElementById('<%= QualMemTypeFromBox.ClientID %>'))) {
(sourceFrom).focus();
}
if (sourceTo == (document.getElementById('MemStatusFromBox'))) {
(sourceFrom).focus();
}
}
<select multiple size="8" style="width: 135px" runat="server" onblur="selectAll(this, true, document.getElementById('<%#uilblDestinationQualOutlet.ClientID%>'))"
id="outletToBox">
</select>
Client-side changes to a ListBox are not persisted server-side, so any changes made will be lost if a PostBack occurs; check out this link to see how you can handle it:
http://www.vijaykodali.com/Blog/post/2007/12/14/Add-Delete-Items-in-DropDownList2c-ListBox-using-Javascript.aspx
If you’re having trouble working with that solution let me know, and post your aspx page code…we can put together a solution for your exact case.