Posted: 5/9/2011
Hi All,I desperately need help with the following:i have a list box control that is populated with dates. This happens on client side(using javascript)but now i need to save the listbox values to the DB which happens at server side on a button click event.My prob is the listbox is empty when i try to do this.Please helpCode is as follows:Client side:listbox<asp:ListBox ID="lstDelDate" runat="server" ViewStateMode ="Enabled" AutoPostBack ="true" > <button type="button" önclick="JavaScript:SelectDate()">Add DeliveryDate</button>The function SelectDate adds the selected calender dates to the listboxplease HelpThanks.
Posted: 5/10/2011
I think that's a normal behavior since you were adding the items at the client-side with javascript. Your server-side code doesn't know anything of what happend at client so when your to access the items it will give you an empty value. What you can do is probably store the items in a HiddenField control so that you can reference the value from there in your server-side code. (you can delimit the values on it if you want to store multiple items). Alternatively you can use AJAX, WebService or Page Methods to call a server-side method from your javascript and pass the items from the ListBox to that method. Just google for it to get more example and information.
Posted: 5/11/2011
Hi,You can take help from jQuery: How to get all selected items of listbox in comma separated string
Posted: 5/24/2011
hi,
you can't get the list box values which you added through javascript,
instead you can do, on the button onclient click event get the selected values using javascript,and assign it to a hidden variable with comma separated, and the value stored in hidden variable you can access from the server side coding.