C# runat=";服务器"+;javascript

C# runat=";服务器"+;javascript,c#,javascript,asp.net,vb.net,C#,Javascript,Asp.net,Vb.net,我的选择框有一个Javascript函数,但在我将runat=“server”包含到该函数中后,脚本调试器将在下面这行突出显示: “表示(i=0;i

我的选择框有一个Javascript函数,但在我将runat=“server”包含到该函数中后,脚本调试器将在下面这行突出显示:

表示(i=0;i
”,并表示:

SCRIPT5007:无法获取属性“length”的值:对象为null或未定义

我包含它是因为我想在代码隐藏中循环它,并执行其他一些操作,请提供建议,谢谢

代码:

    <select multiple size="8" style="width: 135px" runat="server" id="outletFromBox">
                                               <option value="JP">Jurong Point</option>
                                               <option value="IMM">IMM</option>
                                               <option value="Wisma">Wisma</option>                
                                           </select> 
                                       </td>

                                       <td align="center" valign="middle">
                                           <input type="button" class="ui-icon ui-icon-arrowthick-1-e ui-corner-all" style="width: 20px; height: 23px;" onClick=" javascript:move(('outletFromBox'),('outletToBox')); " 
                                                  value=""><br />
                                           <input type="button" class="ui-icon ui-icon-arrowthick-1-w ui-corner-all" style="width: 20px; height: 23px;" onClick=" javascript:move(('outletToBox'),('outletFromBox')); " 
                                                  value=""> 
                                       </td>
   <td style="padding-left: 4px"> 

                                   <select multiple size="8" style="width: 135px" runat="server" onBlur="selectAll(this, true, document.getElementById('<%=uilblDestinationQualOutlet.ClientID%>'))" id="outletToBox">
                                   </select> <span class="guide"></span>
                               </td></tr></table> 


                </div> 
            </asp:Panel>
function move(sourceFrom, sourceTo) {
            var arrFrom = new Array();
            var arrTo = new Array();
            var arrLU = new Array();
            var i;
            for (i = 0; i < sourceTo.options.length; i++) {
                arrLU[sourceTo.options[i].text] = sourceTo.options[i].value;
                arrTo[i] = sourceTo.options[i].text;
            }
            var fLength = 0;
            var tLength = arrTo.length;
            for (i = 0; i < sourceFrom.options.length; i++) {
                arrLU[sourceFrom.options[i].text] = sourceFrom.options[i].value;
                if (sourceFrom.options[i].selected && sourceFrom.options[i].value != "") {
                    arrTo[tLength] = sourceFrom.options[i].text;
                    tLength++;
                } else {
                    arrFrom[fLength] = sourceFrom.options[i].text;
                    fLength++;
                }
            }

            sourceFrom.length = 0;
            sourceTo.length = 0;

            var ii;
            for (ii = 0; ii < arrFrom.length; ii++) {
                var no = new Option();
                no.value = arrLU[arrFrom[ii]];
                no.text = arrFrom[ii];
                sourceFrom[ii] = no;
            }

            for (ii = 0; ii < arrTo.length; ii++) {
                var no = new Option();
                no.value = arrLU[arrTo[ii]];
                no.text = arrTo[ii];
                sourceTo[ii] = no;
            }

            (sourceTo).focus();

            if (sourceTo == (document.getElementById('outletFromBox'))) {
                (sourceFrom).focus();
            }
            if (sourceTo == (document.getElementById('QualMemTypeFromBox'))) {
                (sourceFrom).focus();
            }
            if (sourceTo == (document.getElementById('MemStatusFromBox'))) {
                (sourceFrom).focus();
            }
        }

裕廊坊
IMM
维斯玛

Javascript:

    <select multiple size="8" style="width: 135px" runat="server" id="outletFromBox">
                                               <option value="JP">Jurong Point</option>
                                               <option value="IMM">IMM</option>
                                               <option value="Wisma">Wisma</option>                
                                           </select> 
                                       </td>

                                       <td align="center" valign="middle">
                                           <input type="button" class="ui-icon ui-icon-arrowthick-1-e ui-corner-all" style="width: 20px; height: 23px;" onClick=" javascript:move(('outletFromBox'),('outletToBox')); " 
                                                  value=""><br />
                                           <input type="button" class="ui-icon ui-icon-arrowthick-1-w ui-corner-all" style="width: 20px; height: 23px;" onClick=" javascript:move(('outletToBox'),('outletFromBox')); " 
                                                  value=""> 
                                       </td>
   <td style="padding-left: 4px"> 

                                   <select multiple size="8" style="width: 135px" runat="server" onBlur="selectAll(this, true, document.getElementById('<%=uilblDestinationQualOutlet.ClientID%>'))" id="outletToBox">
                                   </select> <span class="guide"></span>
                               </td></tr></table> 


                </div> 
            </asp:Panel>
function move(sourceFrom, sourceTo) {
            var arrFrom = new Array();
            var arrTo = new Array();
            var arrLU = new Array();
            var i;
            for (i = 0; i < sourceTo.options.length; i++) {
                arrLU[sourceTo.options[i].text] = sourceTo.options[i].value;
                arrTo[i] = sourceTo.options[i].text;
            }
            var fLength = 0;
            var tLength = arrTo.length;
            for (i = 0; i < sourceFrom.options.length; i++) {
                arrLU[sourceFrom.options[i].text] = sourceFrom.options[i].value;
                if (sourceFrom.options[i].selected && sourceFrom.options[i].value != "") {
                    arrTo[tLength] = sourceFrom.options[i].text;
                    tLength++;
                } else {
                    arrFrom[fLength] = sourceFrom.options[i].text;
                    fLength++;
                }
            }

            sourceFrom.length = 0;
            sourceTo.length = 0;

            var ii;
            for (ii = 0; ii < arrFrom.length; ii++) {
                var no = new Option();
                no.value = arrLU[arrFrom[ii]];
                no.text = arrFrom[ii];
                sourceFrom[ii] = no;
            }

            for (ii = 0; ii < arrTo.length; ii++) {
                var no = new Option();
                no.value = arrLU[arrTo[ii]];
                no.text = arrTo[ii];
                sourceTo[ii] = no;
            }

            (sourceTo).focus();

            if (sourceTo == (document.getElementById('outletFromBox'))) {
                (sourceFrom).focus();
            }
            if (sourceTo == (document.getElementById('QualMemTypeFromBox'))) {
                (sourceFrom).focus();
            }
            if (sourceTo == (document.getElementById('MemStatusFromBox'))) {
                (sourceFrom).focus();
            }
        }
函数移动(sourceFrom,sourceTo){
var arrFrom=新数组();
var arrTo=新数组();
var arrLU=新数组();
var i;
对于(i=0;i
将runat=“server”添加到任何控件时,控件的客户端id将更改。 我想这是您的问题,您应该将客户端ID传递给move函数