views:

427

answers:

1

Hello all!

I've 2 asp listbox controls and an html input button, and using js i add items (previously loaded from DB) from listbox A to B and it works fine, but when i submit the form, in the code behind the listbox B do not have the item i added accessible.

My idea was trying to save roundtrips to the server and make it in client side but looks like it doesn't work.

Any ideas?

Thanks you very much for you time!

EDIT

There's the code

<asp:ListBox ID="lstBoxOrgs" runat="server" Height="117px"  Width="502px" SelectionMode="Multiple"></asp:ListBox>
<input type="button" value="Add" onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') "/>

Code behind:

protected void AssignOrgs_Click(object sender, EventArgs e)
{
    foreach (ListItem orgItem in lstBoxUserRelOrgs.Items)
    {
     //Update database here...
    }

    //Commit updates to DB
    cdc.SubmitChanges();
}

The onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') is the javascript function that adds the items from lisbox A to listbox B.

Thanks

+3  A: 

You have two options. First option is to keep track of what options were added in hidden variables and read that on the server.

The second option is to select all of the options when the page submits and use Request.Form to get the values of the options in the list.

You can not reference your select like you always do in the backend since the viewstate has no clue that options were added/removed.

epascarello