简体   繁体   中英

Listbox items always getting 0 count on server side

I have two listboxs , and two buttons . The buttons will transfer 1 item from listbox1 to listbox2 .

$(function () {
    $("#btnLeft").bind("click", function () {
        var options = $("[id*=listBoxRight] option:selected");
        for (var i = 0; i < options.length; i++) {
            var opt = $(options[i]).clone();
            $(options[i]).remove();
            $("[id*=listBoxLeft]").append(opt);
            return false;
        }
    });
    $("#btnRight").bind("click", function () {
        var options = $("[id*=listBoxLeft] option:selected");
        for (var i = 0; i < options.length; i++) {
            var opt = $(options[i]).clone();
            $(options[i]).remove();
            $("[id*=listBoxRight]").append(opt);
            return false;
        }
    });
});

This code is working and is transferring items from one another in the client side. My problem is when I get the value at the server side, I get 0 count.

Is it possible to bind the new items of listbox2 using jQuery ?

EDIT

I am using a user control:

The control is ShutterUserControl , and it contains two listboxs .

Make your listbox runat server.

<select id="listboxRight" runat="server">
      <option>text1</option>
      <option>text2</option>
</select>

Then use following thing with Request.form. For that in your above JavaScript you need to use ClientID like <%=listBoxRight.ClientID%> .

Then you find that user control via two way one is with Request.Form

Request.Form["YourUserControlName$listboxRight"]

Another is

 var listBox = YourUserControlName.FindControl("listboxRight");

Hope this will help.

尝试Request.Forms["controlName"]dropdown列表中获取新值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM