473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with listbox at client side

Hi Group,

In my application there is a very common functionality, where two list
box and present and items are moved between them on button clicks when
selected,

This I am doing client side,
Client side code is like this ->

function
assignInspector(listboxAllFieldEngineers,listBoxAs signedFieldEngineers)
{
i=0;
while(i<listboxAllFieldEngineers.length)
{
if(listboxAllFieldEngineers.options[i].selected)
{
var optn = document.createElement("OPTION");
optn.text = listboxAllFieldEngineers.options[i].value;
optn.value = listboxAllFieldEngineers.options[i].value;
listBoxAssignedFieldEngineers.options.add(optn);
listboxAllFieldEngineers.remove(i);
continue;
}
i++;
}
return false;
}
Here two list boxes are passed from .CS file ->

buttonAddSelected.Attributes.Add("onclick","return
assignInspector(listboxAllFieldEngineers,listBoxAs signedFieldEngineers);");

PROBELM:-

Items move from one listbox to other perfectly but when listboxes are
accessed through .cs file, they show there previous state,

e.g. ->

say LeftListBox is having 4 items and RightListBox is having 2
elements,
now I select and move two items from left and move them ro right and
one of previously present items from right to left on button click,

the client side operation is carried out perfectly,

But when I try to use the Items in RightListBox in .CS
file,RightListBox.Items.Count returns only '2' instead of '3', which
are previously present in the RightListBox.
Please tell me where I am going wrong(Using ASP.NET 1.x).
Thanks and Regards,

Anup Daware

Apr 18 '06 #1
5 2547
You might be loading data on load ...try filterering on IsPostBack
....also please check viewstate of the controls

- hungrymind

Apr 18 '06 #2
thank you for quick reply,
But, viewstste is true for listboxes and leftside list box list-box is
populated in if( !PostBack )
please let me know if you can suggest any thing else..

Thanks and Regards,

Anup Daware

Apr 18 '06 #3
Hi,

IMO you will have to do all this client side, so use a regular html SELECT
(you can still use a listbox )
This is what I would do:
1- Assign the values in the server side as usual
2- in the client the onclick of the button will call a jscript method that
will delete/insert an item from one listbox to the other.
3- before postback create a string concatenating the values of either both
or one of the listboxes. Usually using a HIDDEN control
4- in the server side use this string to know the content of one or both of
the listboxes
I have done this several times in ASP

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Apr 18 '06 #4
Hi Ignacio,

This is really a very useful post, but I have some confusion, I am new
to ASP.NET and I have little difficulty in using hidden controls, I
mean how do I store the values at client side and pass them to server
using hidden controls?

Please provide some sample code you used if possible.

Thanks,
Anup

Apr 19 '06 #5
Hi,

"Anup" <an*********@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi Ignacio,

This is really a very useful post, but I have some confusion, I am new
to ASP.NET and I have little difficulty in using hidden controls, I
mean how do I store the values at client side and pass them to server
using hidden controls?


you declare it like this in the page:
<input type="hidden" name="MinDate" id="MinDate" value="01/01/2003"
runat=server>

and like this in the code behind:

protected System.Web.UI.HtmlControls.HtmlInputHidden MinDate;
then you can access the value using MinDate.Value

before you submit your form you build the value of the control and it will
be accesible in the code behind.

Sorry I cannot provide you with a working example right now, I will have to
look around to find one, I have use this technique in several instances,
maybe later today I can provide you with one.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
3
by: me | last post by:
Is there any particular reason why a requiredfieldvalidator cant validate a listbox? I have bound the two together but the validator always returns false on isvalid and so does the Page, no matter...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
5
by: Eddie Clark | last post by:
I'm trying to access the items in a listbox from a client-side vb script. <asp:listbox id="ListBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 120px" runat="server" Width="400px"...
2
by: Simon Prince | last post by:
Help I have a ASP:Listbox on a form. My page Adds items to this this via Client-Side Script only. Such as... var vObj_TargetElement =...
3
by: Stimp | last post by:
I have a listbox of values that I populate from a database. I want the user to be able to re-order the list (by first selecting an item and then clicking 'up' or 'down' buttons) and then save...
10
by: Mr Newbie | last post by:
DropDown lists and Listboxes do not appear in the list of controls and values passed back to the server on PostBack in Request.Form object. Can someone confirm this to be correct and possibly...
2
by: Anup | last post by:
Hi Group, In my application there is a very common functionality, where two list box and present and items are moved between them on button clicks when selected, This I am doing client side,...
3
by: Brian Simmons | last post by:
Hi All, I search on codeproject and google but didn't find what I was looking for. Anybody know of a good implementation where you have 2 listboxes and you want to move items between the 2. ...
4
by: bogdan | last post by:
Hi, I have two listboxes on a page and need to move items between them - using buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net? I'd like to avoid hitting the server on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.