2011-11-01 62 views
0

我有2間移動項目選擇多箱,當我從源選擇框目的地選擇框移動項目的JavaScript函數,我的價值添加到我的HiddenField讓我能在代碼訪問的背後,工作正常,但當我從目的地選擇框回源選擇框移到項目(S),我嘗試使用:hidMemType.value =「」;清除隱藏區域。我認爲這有效,但顯然在發生回發時,該項目仍然卡在目的地框中。請指教,謝謝。HiddenField值不會被刪除

// Move items to and fro select box 
     function move(sourceFrom, sourceTo) { 

      var hidOutlet = document.getElementById('<%=hdnOutlet.ClientID%>'); 
      var hidMemType = document.getElementById('<%=hdnMemType.ClientID%>'); 
      var hidMemStatus = document.getElementById('<%=hdnMemStatus.ClientID%>'); 

      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; // SENDS VALUE FROM DESTINATION BOX BACK TO SOURCE BOX 
      hidMemType.value = ""; // TRY TO CLEAR MY HIDDEN FIELD HERE 
      } 


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

       if (sourceTo == (document.getElementById('<%=outletToBox.ClientID%>'))) { 
        hidOutlet.value += no.value + "|"; 
       } 
       if (sourceTo == (document.getElementById('<%=QualMemTypeToBox.ClientID%>'))) { 
        hidMemType.value += no.value + "|"; 
       } 
       if (sourceTo == (document.getElementById('<%=MemStatusToBox.ClientID%>'))) { 
        hidMemStatus.value += no.value + "|"; 
       } 
      }    



     (sourceTo).focus(); 

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

} 

代碼背後:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

PopulateSelectBoxes(hdnMemType, QualMemTypeToBox, QualMemTypeFromBox) 

end Sub 

Protected Sub PopulateSelectBoxes(ByVal hdnSelectBox As HiddenField, ByVal selectBox As HtmlSelect, ByVal selectBox_Frm As HtmlSelect) 

    Dim hiddenMemType(selectBox.Items.Count - 1) As String 
     hiddenMemType = (Split(hdnSelectBox.Value, "|")) 

     Dim tempTable As String = "" 
     For Each item In hiddenMemType 
      If (tempTable.IndexOf(item) = -1) Then 
       If item <> "" Then 
        tempTable += item + "|" 
       End If 
      End If 
     Next 

     If tempTable <> "" Then 
      hiddenMemType = (Split(tempTable, "|")) 

      'We remove the items that exist in the ToBox 
      For Each item In hiddenMemType 
       selectBox_Frm.Items.Remove(item) 
      Next 

      selectBox.Items.Clear() 
      selectBox.DataSource = hiddenMemType 
      selectBox.DataBind() 
     End If 

    End Sub 

回答

0

只是想大聲這裏。 有你的代碼試圖在這背後:

myControl.value = Nothing 

也許會工作。

編輯: 你也可以嘗試在其中放置一個默認值,如果它的默認值,你只是不做任何事情。如果你與當前值做到了將其改回默認

0

嘗試在你的隱藏控件禁用ViewState的 - 也許這是什麼保留價值。

0

在你的JS move函數中,我想象for循環跟在hidMemType.value = "";之後的是再次設置hidMemType.value。你有沒有檢查過,情況並非如此?我會附上該for環在if,以確保當它不應該是它沒有擊中。

我還會在function move()的末尾添加alert以準確顯示hidMemType.value正在退出。