2013-04-26 130 views
0

我有一個應用程序,它是在.Net1.1並升級到3.5使用Visual Studio 2008列表框的Javascript Multtiselect不工作後升級到.NET 3.5

有由具有一個複選框和一個列表框頁面這是啓用和禁用使用Javascript,如果啓用我們可以選擇列表中的項目,並在按鈕點擊選定的項目將被處理。

選定的項目工作正常,在NET 1.1,但不是在3.5.I我給在那裏我對着issue.The相同的代碼示例代碼工作正常,在.Net1.1

下面是ASPX線

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListBox.aspx.cs" Inherits="WebApplication1.ListBox" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head> 
     <title>UsageReport</title> 
     <script language="javascript"> 
      function isAllChecked() 
      { 
       var ctrlList = document.getElementById("lstUsers"); 
       var allChecked = document.getElementById("chkAll"); 
       var checked = allChecked.checked; 

       if (checked) { 

        ctrlList.disabled = true; 
        unselectItems(); 
       } 
       else { 

        ctrlList.disabled = false; 

       } 
      } 

      function unselectItems() 
      { 
       var lstUsers = document.getElementById("lstUsers"); 
       var list = lstUsers; 

       for (var i = 0; i < list.length; i ++) 
       { 
        list[i].selected = false; 
       } 
       list.selectedIndex = -1; 
      } 
     </script> 
    </head> 

<body> 
    <form id="form1" runat="server"> 
    <div> 
    </div> 
    <table> 
     <tr> 
      <td> 
       &nbsp;</td> 
      <td> 
     <asp:CheckBox ID="chkAll" Checked="True" runat="server" /> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       &nbsp;</td> 
      <td> 
     <asp:ListBox ID="lstUsers" runat="server" SelectionMode="Multiple" Enabled="false"></asp:ListBox> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       &nbsp;</td> 
      <td> 
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
      </td> 
     </tr> 
    </table> 
    </form> 
</body> 
</html> 

下面是代碼隱藏

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace WebApplication1 
{ 
    public partial class ListBox : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
      { 
       this.chkAll.Attributes["onclick"] = "isAllChecked();"; 
       lstUsers.DataSource = new string[] { "one", "two", "three" }; 
       lstUsers.DataBind(); 
      } 
     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      foreach (ListItem li in lstUsers.Items) 
      { 
       if(li.Selected) 
       Response.Write(li.Value); 
      } 
     } 
    } 
} 

回答

0

線之後做一些研究,問題是與列表框默認情況下禁用,如ASP.Net 3.5不允許SUBM它對禁用控制的更改是根本原因。

它被從列表框中

<asp:ListBox ID="lstUsers" runat="server" SelectionMode="Multiple"> </asp:ListBox> 

取出啓用=「假」一種解決辦法的工作,並通過調用體

<body onload="isAllChecked()" > 

的黑客的JavaScript的onload來達到的相同的功能我在這裏做的是因爲ASP.Net允許對禁用控件進行任何更改,以便在服務器上啓用該控件,但從客戶端腳本中禁用它,使其禁用

我也試過在表單標籤中使用submitdisabledcontrols =「true」,但對我無用