I have an ASP.Net ListBox that I am trying to populate through jQuery using the following snippet:
$("#MyList_btnAddAll").click(function(e) { e.preventDefault(); $('#MyList_lstAll option').appendTo('#MyList_lstSelected'); });
There are two ListBoxes in the code, one of which is the "source" and the other is the "destination". As you can say above, ListBoxes are MyList_lstAll and MyList_lstSelected. They appear in the browser as elements, as you would expect.
jQuery works fine, items move from one ListBox to another, the DOM is updated, but when I submit my page, postback does not indicate any changes to the ListBox. I know there are gotchas involving jQuery and ASP.Net postbacks, but can anyone reflect on what is happening and how can I make this work?
[EDIT]
Upon request, several more ASP.Net and HTML appear here. ListBox declarations and buttons in the ascx control that contains them are listed below:
<GLP:ListBox ID="lstAll" CssClass="LIST_BOX_MEDIUM" runat="server" SelectionMode="Multiple"/> <asp:LinkButton ID="lnkAddAll2" CssClass="LIST_SELECT" runat="server" OnClick="btnAddAll_Click"/> <GLP:ListBox ID="lstSelected" CssClass="LIST_BOX_MEDIUM" runat="server" SelectionMode="Multiple"/>
And the resulting HTML:
<select class="LIST_BOX_MEDIUM" id="MyList_lstAll" multiple="multiple" name="MyList:lstAll" size="4"> <option value="641">Item1</option><option value="598">Item2</option> </select> <input type="submit" class="BUTTON_SMALL_N0_IMAGE" id="MyList_btnAddAll" value="Add All" name="MyList:btnAddAll" style="color: rgb(0, 0, 0);"> <select class="LIST_BOX_MEDIUM" id="MyList_lstSelected" multiple="multiple" name="MyList:lstSelected" size="4"> <option value="642">Item3</option><option value="599">Item4</option> </select>
I know that changes to the jQuery / ListBox are not reflected in the ViewState, but since they are in the DOM when the page is published, they will not be included in the postback data and then matched by the appropriate controls?
source share