tags:

views:

21

answers:

1

Hi,Im adding items to listbox by using jquery but when i look to the page source(html source) ,the items that I've added dont seen.Im adding items by this way

$("#<%=ListBox2.ClientID%>").append("<option value="+exampleValue+">"+exampleName+"</option>");
+2  A: 

You need quotes on attributes, like this:

$('#<%=ListBox2.ClientID%>')
    .append('<option value="' + exampleValue + '">' + exampleName + '</option>');

Also, depending on the browser, it will show the original page's source when you do "View Source"

As an aside: there is a faster approach if adding many elements, since jQuery will cache the fragment:

$('#<%=ListBox2.ClientID%>')
   .append($("<option></option>").attr("value",exampleValue).text(exampleName)); 
Nick Craver
Thanks for your help,I have done what u said,but still page source doesnt seen correctly and also when i want to reach listbox items from code side(c#) ,it still returns the original items of listbox.The ones I have added dont seen in the code side
slayer35
@slayer - Postbacks don't work this way, that's an entirely different set of elements..all that's passed to the server are the list items that you selected, not all of them. E.g. if you create 20 items, none will be sent to the server unless selected, and then only their value. You need to create/bind the ListItems server-side to have them present in your code-behind.
Nick Craver