I’m adding values, to a listbox, with jquery’s Append. I simply write an option, in HTML, and append it, on a button click.
Now, once the page posts, I would like to store these values, in my database. However, it seems like the Listbox is empty. When I view source, it also appears empty. I guess I don’t fully understand the client side concept.
How do I get these non-existing values, into my code-behind?
This is the add function:
function AddGPWNum() {
var TestNum = $("#<%= TestNumText.ClientID %>").val();
if (TestNum.length == 0)
return false;
var NewString = TestNum.split("<");
NewString = NewString.join("<");
$("#<%= TestNumText.ClientID %>").val("");
TestNum = '<option value="' + NewString + '">' + NewString + '</option>';
$("#<%= TestNumList.ClientID %>").append(TestNum);
$("#<%= HiddenNumbers.ClientID %>").val() = $("#<%= TestNumList.ClientID %> > option").map(function () { return this.value }).get().join(',');
return false;}
asp.net will only see the added values if they are chosen by the user as they are then returned as part of the
Requestcollection.If jQuery adds values to the listbox then you will not see them if you do a ‘view source’ on your page as they have been dynamicaly added to the DOM. You may ser them if you view the source with a tool like Firebug.
If you want to see the values you’ve added in the code-behind you could append the values you add to a hidden field as well as the listbox, the value of the hidden field would then be available in the code-behind and you could parse the values from that.
jQuery similar to this should write a comma seperated list of the listbox values into a hidden field –