1

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

1
  • please add your code (or a simple case of it) and then it is much easier for us to help you. Commented Oct 27, 2009 at 10:00

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.