asp.net - What wrong in this code? -


here have 2 list boxes ,when click add button items should added second list box in asp.net using jquery.

    <%@ page language="c#" autoeventwireup="true" codefile="listboxexample.aspx.cs" inherits="listboxexample" %>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>adding,removing elements first listbox second listbox</title>     <style type="text/css">         .lstbx1         {             font-family: verdana;             font-size: medium;             font-style: normal;             background-color: aqua;             height: auto;             width: auto;         }         .lstbx2         {             font-family: verdana;             font-size: medium;             font-style: normal;             background-color: lime;             height: auto;             width: auto;         }     </style>     <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js" />     <script type="text/javascript">         function move_elements() {             $("#lstbx1").appendto("#lstbx2");         }      </script> </head> <body>     <form id="form1" runat="server">     <div>         <table>             <tr>                 <td>                     <asp:listbox id="lstbx1" runat="server" cssclass="lstbx1" selectionmode="multiple">                         <asp:listitem>one</asp:listitem>                         <asp:listitem>two</asp:listitem>                         <asp:listitem>three</asp:listitem>                         <asp:listitem>four</asp:listitem>                         <asp:listitem>five</asp:listitem>                         <asp:listitem>six</asp:listitem>                         <asp:listitem>seven</asp:listitem>                     </asp:listbox>                 </td>                 <td>                     <asp:listbox id="lstbx2" runat="server" cssclass="lstbx2"></asp:listbox>                 </td>             </tr>             <tr>                 <td>                     <asp:button id="btnadd" runat="server" text="add" onclientclick="move_elements();" />                 </td>                 <td>                     <asp:button id="btnremove" runat="server" text="remove" onclientclick="" />                 </td>             </tr>         </table>     </div>     </form> </body> </html> 

<script type="text/javascript">     function move_elements() {         var originallist = $("#<%= this.lstbx1.clientid %>");         var items = $('option', originallist);         var targetlist = $("#<%= this.lstbx2.clientid %>");         items/*.clone()*/.appendto(targetlist);     }  </script> 

working example

edit:
anyway, want warn you, not able access items in code-behind, because these serialized in viewstate , not taken actual rendered control.
result: if add n items javascript , have 1 of these newly-added items selected selecteditem in ui, asp.net-engine fail map selectedvalue @ server-side item of box, because not have these items in viewstate!


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -