could any body explain me how can i save state of two list boxes on post back i am using jQuery of this kind i dont know on what event what should i do or where can i save view state or how can i use hiddenField to persist the state of both list box
<script language="javascript" type="text/javascript">
$(document).ready(function() {
//If you want to move selected item from fromListBox to toListBox
开发者_JAVA百科 $("#add").click(function() {
$("#"+'<%= fromListBox.ClientID %>'+" option:selected").appendTo("#"+'<%=toListBox.ClientID %>');
});
//If you want to move all item from fromListBox to toListBox
$("#addAll").click(function() {
$("#"+'<%= fromListBox.ClientID %>'+" option").appendTo("#"+'<%=toListBox.ClientID %>');
});
//If you want to remove selected item from toListBox to fromListBox
$("#remove").click(function() {
$("#"+'<%=toListBox.ClientID %>'+" option:selected").appendTo("#"+'<%= fromListBox.ClientID %>');
});
//If you want to remove all items from toListBox to fromListBox
$("#removeAll").click(function() {
$("#"+'<%=toListBox.ClientID %>'+" option").appendTo("#"+'<%= fromListBox.ClientID %>');
});
});
</script>
<asp:ListBox ID="fromListBox" runat="server" SelectionMode="Multiple" Height="150px" Width="150px" >
<asp:ListItem Text="Student Enrollment ID" Value="enrollment_no"></asp:ListItem> <asp:ListItem Text="Student Name" Value="first_name"></asp:ListItem> <asp:ListItem Text="Last Name" Value="last_name"></asp:ListItem> <asp:ListItem Text="Father Name" Value="father_name"></asp:ListItem>
</asp:Listbox>
<asp:ListBox runat="server" ID="toListBox" ></asp:ListBox>
I think you just should use normal html listboxes, not asp.net server controls. Here are some tips about it. And here you can find decent code for jquery that will move items beetween listboxes.
I think you have three options:
- Use normal HTML listboxes, write some javascript code, and manipulate with them on server using standard POST request.
- Use UpdatePanel with your listboxes (you'll eliminate page flickering and you probably wont have to use jQuery or rewrite your existing code)
- Find or write your own control that uses javascript to move items and manage viewstate itself
I would use HTML listboxes (select elements) to avoid viewstate issues. It'll save you a lot of time.
精彩评论