我在服务器端从数据库中获取到数据,添加到listBox
在客户端又删除了一些listbox的项
但这样保存的时候,在后置代码中读取的还是原来服务器端添加上的那些数据
怎么样在JS中删除listbox项后,能通知服务器端     function delteSelect()
     {        var list = document.getElementById("<%=listboxFile.ClientID %>");
        for( i=0;i< list.length; i++ )
        {
            if(list.options[i].selected)
            {
               list.remove(i);
            }
        }
     }在网上有这段代码:
                var url = window.location.href;
                
                 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
                 xmlhttp.open("POST",url, true);   
                 xmlhttp.send(); 不知道怎么用

解决方案 »

  1.   

    在服务器端从数据库中获取到数据,添加到listBox 添加的代码放到
    if(!IsBackPost)里面就不会有这种问题了
      

  2.   

    脚本端循环ListBox 拼成一个字符串赋到一个隐藏的input中
    后台Request取值
    function saveselected(){
    var tempStr;
    tempStr = ",";
    for( var i = 0; i < document.Form1.ListBox1.options.length; i++ ) 

      if ( document.Form1.ListBox1.options[i] != null ){
         tempStr = tempStr + document.Form1.ListBox1.options[i].value+",";}
    }
    document.Form1.NoSelected.value = tempStr;
      }
    记得在返回服务器之前加载...
    如:Button1.Attributes.Add("onclick","saveselected()");