简体   繁体   English

列表框项始终在服务器端计数为0

[英]Listbox items always getting 0 count on server side

I have two listboxs , and two buttons . 我有两个listboxs和两个buttons The buttons will transfer 1 item from listbox1 to listbox2 . buttons会将1项从listbox1传输到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. 我的问题是,当我在服务器端获取值时,我得到了0个计数。

Is it possible to bind the new items of listbox2 using jQuery ? 是否可以使用jQuery绑定listbox2的新项目?

EDIT 编辑

I am using a user control: 我正在使用用户控件:

The control is ShutterUserControl , and it contains two listboxs . 该控件是ShutterUserControl ,它包含两个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. 然后将以下内容与Request.form一起使用。 For that in your above JavaScript you need to use ClientID like <%=listBoxRight.ClientID%> . 为此,您需要在JavaScript中使用<%=listBoxRight.ClientID%>类的ClientID。

Then you find that user control via two way one is with Request.Form 然后,您发现用户控件通过两种方式之一是与Request.Form一起使用

Request.Form["YourUserControlName$listboxRight"]

Another is 另一个是

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

Hope this will help. 希望这会有所帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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