开发者

listbox and javascript to add items

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜