tags:

views:

116

answers:

1

I've two ListBox (second one is empty on page load) and two buttons which switch items between those ListBox.However,im using Jquery two switch items,which means there are no Postbacks.Once,ive finished,i click another button to save the items from the second List,this time using PostBack.

When it runs on server,ASP.NET does not recognize any item on the list,showing listbox2.items.count = 0(zero),but im sure that list does have items.

I wonder if add items to the list without postbacks is the problem;

Any suggestions?

code trying to get list:

   try
    {
        estabelecimentos = new List<int>();
        int x = lstSelect.Items.Count;//always 0,but list isnt empty
        estabelecimentos = lstSelect.Items.Cast<ListItem>().Select(v => int.Parse(v.Value)).ToList();      
    }
    catch(Exception ex)
    {
        divErro.Visible = true;
        lblErro.Text = ex.Message;
        return;
    }
+1  A: 

You are correct, when you postback to the server the datasource of the second list is read out of the ViewState (which had no items in it). You could store the second list's data in a hidden input (client side) or you could do postbacks to update the second list.

Matt Dearing
hidden input was a fine solution thk