Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

HTML
<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
Updated 9-May-11 1:48am
v2
Comments
Ankur\m/ 9-May-11 6:20am    
ViewStateMode = "Enabled"
I don't see such attribute available for me in VS.
Ankur\m/ 9-May-11 6:31am    
Does the ListBox gets populated properly with the required values?
AnnSJ 9-May-11 7:41am    
Such a property exists.. yes the listbox does get the selectd dates
Ankur\m/ 9-May-11 7:50am    
You have called SelectDate() function on click of the button? Don't you want it pre-loaded i.e when the page loads? I guess you would want to move it to body onload.
Ankur\m/ 9-May-11 7:52am    
Try this,
Add return true; after the listbox gets populated in the JavaScript function.
And call the method OnClientClick of the Button like this - OnClientClick="return populateListBox();"

Let me know if that helps.

1 solution

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    For i As Integer = 0 To ListBox1.Items.Count - 1
        'Here you would do the code that would pass it to the database to be saved
    Next
End Sub


This should give you the general idea of what you need to do if you need more help then just shout.
 
Share this answer
 
Comments
AnnSJ 9-May-11 7:59am    
Hi Simon.. yes i have already doen that but my prob is Listbox1.items.count is 0 even after being populated
Simon_Whale 9-May-11 8:09am    
your code snippet shows the list box to be lstDelDate does that control have a count?
AnnSJ 9-May-11 8:46am    
my prob exactly.the count is 0 even after i populate it with values

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900