Question

I am implenting some functionality on asp.net page such that: There are to listboxes side by side, left one is prepopulated and right one is empty. Besides left listbox there is add button and besides right there is remove button. I have written javascript code such that on Add button click the selected listItems from left listbox are moved to right listbox and vice-versa.

It is as follows:

enter image description here

When I submit the form, in code-behind I am not able to retrive the newly moved values from right ListBox (I know its not posssible in this way). How can I access the changes made with the javascript changes to the listboxes in the codebehind.

Any help appreciated.

Was it helpful?

Solution 2

<form id="form1" runat="server">
    <div>
        <select id="greet" name="greet" multiple="multiple">
            <option>Mr</option>
            <option>Mrs</option>
            <option>Miss</option>
            <option>Dr</option>
        </select>
        <asp:Button Text="Submit" runat="server" ID="btnSubmit" 
                            OnClick="btnSubmit_Click" />
    </div>
</form>


 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string greets = Request["greet"];

    }

I was able to view the selected items in the list

OTHER TIPS

I think while you are loading the page contents inside Page_Load(),make sure that you are loading after checking whether is a post back request or not.Load the events if it is not a postback request.

i.e :-

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
       {

        //load the contents of the page/listbox here.

       }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top