469,642 Members | 1,174 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

unable to retrieve listbox items on postback , items moved usingjavascript between 2 list boxes (source and target )


I used the below code to move selected items between two listboxes
Left and Right:-

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
- Function MoveItems()
- Direction: Specifies direction i.e. L = Left, R = Right
- All: Move All items 1 = All, 0 = Selected
function MoveItems(Direction, All)
var LstLeft;
var LstRight;
var Removed = '';
var i;

if (Direction == 'R')
var LstLeft = document.getElementById("<
%=LstLeft.ClientID %>");
var LstRight = document.getElementById("<
%=LstRight.ClientID %>");
var LstLeft = document.getElementById("<
%=LstRight.ClientID %>");
var LstRight = document.getElementById("<
%=LstLeft.ClientID %>");

for (i=0; i<LstLeft.length; i++)
if (LstLeft.options[i].selected || All == 1)
if(ItemExists(LstRight, LstLeft.options[i].value)
== 0)
LstRight[LstRight.length] = new
Option(LstLeft.options[i].text, LstLeft.options[i].value, true);
Removed = Removed + LstLeft.options[i].value +
RemoveFromList(LstLeft, Removed);
return false;

function RemoveFromList (Lst, Items)
var Removed = Items.split(',');
var j;
var x;
for (j=0; j<Removed.length; j++)
for (x=0; x<Lst.length; x++)
if (Lst.options[x] != null && Lst.options[x].value
== Removed[j])
Lst.options[x] = null;

function ItemExists(Lst, value)
var Flag = 0;
var i = 0;
for (i=0; i<Lst.length; i++)
if (Lst.options[i].value == value)
Flag = 1;
return Flag;
<form id="form1" runat="server">
<asp:ListBox ID="LstLeft" runat="server"
SelectionMode="multiple" Width="200px" Rows="5" >
<asp:ListItem Value="0" Text="Farhan"></asp:ListItem>
<asp:ListItem Value="1" Text="Moin"></asp:ListItem>
<asp:ListItem Value="2" Text="Haroon"></asp:ListItem>
<asp:ListItem Value="3" Text="Khurram"></asp:ListItem>
<asp:ListItem Value="4" Text="Mansur"></asp:ListItem>
<asp:ListBox ID="LstRight" runat="server"
SelectionMode="multiple" Width="200px" Rows="5">
<br />
<asp:Button ID="BtnRight" runat="server" Text=">"
OnClientClick="return MoveItems('R', 0);" />
<asp:Button ID="BtnLeft" runat="server" Text="<"
OnClientClick="return MoveItems('L', 0);"/>
<asp:Button ID="BtnRightAll" runat="server" Text=">>"
OnClientClick="return MoveItems('R', 1);" />
<asp:Button ID="BtnLeftAll" runat="server" Text="<<"
OnClientClick="return MoveItems('L', 1);" />

I am unable to retrieve the items of the listbox on postback which are
filled using the javascipt code as shown above.
I am able to retrieve all the other fields values on postback , but
these two listboxes don't show the updated count and items list.The
rightbox items count on postback is zero though the items are moved
into it from the left listbox.
I am using EnableEventValidation="false" .

Please help me with how to retrieve the updated listbox items on

Thanks ,
Jun 27 '08 #1
1 3442
Hi divya.

I am not sure about what went wrong. please try the bellow

Please use a hidden input field in your page, while moving the items
in right listbox in javascript
save the itemvalues in a comma or semicolon separated way in the
hidden field.
After postback, In "Page_load" event check the hidden input's value,
and modify both list box ....

Best of luck

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stimp | last post: by
7 posts views Thread by Ohad Asor | last post: by
9 posts views Thread by zdrakec | last post: by
7 posts views Thread by Lit | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.