Loading ...

Listbox values on server side

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » Listbox values on server side

Listbox values on server side

Posts under the topic: Listbox values on server side

Posted: 5/9/2011

Lurker 5  points  Lurker
  • Joined on: 4/28/2011
  • Posts: 1

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 help
Code 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 listbox
please Help
Thanks.


Posted: 5/10/2011

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

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

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490
  Answered

Posted: 5/24/2011

Lurker 125  points  Lurker
  • Joined on: 5/24/2011
  • Posts: 9
  Answered

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.

 

 


Page 1 of 1 (4 items)