views:

58

answers:

2

I'm moving itmes from one ASP.NET ListBox control to another ListBox control from client-side. It works on the client-side but when I tried to count items in destination ListBox on the server-side, it's always nothing. Below, is the jQuery code used to add/remove items from ListBox control.

<script type="text/javascript">
    $(document).ready(function(addToList) {
    // to move selected item from lbSource to lbDestination
    $("#add").click(function() {
    $("#lbSource  option:selected").appendTo("#lbDestination").attr("selected", false);
    });

    // to remove selected item from lbDestination to lbSource
    $("#remove").click(function() {
    $("#lbDestinaion option:selected").appendTo("#lbSource").attr("selected", false);
    });
});
</script>

I know that we can add/remove items from ListBox from server-side. But I'd like to get it done from client-side.

Why there isn't anything in the destination ListBox when counting the items from the code-behind, eventhough the items are added from the client-side already.

A: 

Javascript modifications that is made on controls won't be shown on the server side. I think that it is related to asp.net life circle. However it is shown in hidden fields. So you can track it on the server side if you will add information in additional hidden fields, for instance you can save ids or names of the options in hidden fields.

Danil
A: 

Even it is showing in the client side, it is not submitted to the server, values are not updated in the server.Are you performing any action to update the list, like running update db sql??

If you want to do this with out page submit , Use Ajax.

zod