2015-10-14 69 views
0

禁用列表框,我試圖禁用我的網頁形式的負載兩個列表框,但列表框不禁止。我嘗試了下面的代碼,但它仍然不適用於我的案例。請讓我知道我要去哪裏錯了。上的Page_Load

設計器代碼

<telerik:RadListBox ID="lbSelectedDepartmentContacts" runat="server" Width="220px" AutoPostBackOnTransfer="true" AutoPostBackOnReorder="true" AutoPostBackOnDelete="true" CheckBoxes="false" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbDepartmentContacts" 
                      Height="276px" SelectionMode="Single" AllowReorder="True"> 
                      <ButtonSettings ShowTransfer="false" ShowTransferAll="false" ReorderButtons="Common" ShowReorder="true" /> 
                     </telerik:RadListBox> 
                    </td> 
                   </tr> 
                   <tr> 
                    <td align="right"> 
                     <telerik:RadListBox ID="lbDepartmentContacts" runat="server" Width="200px" CheckBoxes="false" AutoPostBackOnTransfer="true" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbSelectedDepartmentContacts" 
                      Height="250px" SelectionMode="Single"> 
                      <ButtonSettings TransferButtons="Common" ShowTransfer="false" ShowTransferAll="false" /> 
                     </telerik:RadListBox> 

BACKCODE

public void DisableControls() 
     { 
System.Text.StringBuilder sb = new System.Text.StringBuilder(); 
      sb.Append(@"<script language='javascript'>function DisableControls(){"); 
      sb.Append(@"var lbl = document.getElementById('lbSelectedDepartmentContacts').disabled = true;"); 
      sb.Append(@" var Txt = document.getElementById('txtDepartmentCategoryContactsFilter').disabled = true;"); 
      sb.Append(@" var btn = document.getElementById('RadButton1').disabled = true;"); 

      sb.Append("}</script>"); 

      if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock")) 
      { 
       ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", 
       sb.ToString()); 
      } 

      string funcCall = "<script language='javascript'>DisableControls();</script>"; 

      if (!ClientScript.IsStartupScriptRegistered("JSScript")) 
      { 
       ClientScript.RegisterStartupScript(this.GetType(), "JSScript", funcCall); 
      } 
} 

也嘗試:

Page.ClientScript.RegisterStartupScript(this.GetType(), "text", "DepartmentLoad();", true); 

JavaScript代碼

function DepartmentLoad(){ 
      document.getElementById("lbSelectedDepartmentContacts").disabled = true; 
      document.getElementById("lbDepartmentContacts").disabled = true; 
      document.getElementById("txtDepartmentCategoryContactsFilter").disabled = true; 
      ducument.getElementById("RadButton1").disabled = true;} 
+1

你得到你的瀏覽器控制檯任何JS錯誤? – halfer

+0

爲什麼不使用C#代碼來禁用ListBox? –

+0

沒有我沒有得到任何錯誤。我沒有使用C#代碼來禁用列表框,但沒有任何工作 – Boity

回答

1

C#唯一的方法來禁用2個列表框...

刪除或註釋掉現有DisableControls()方法然後添加以下...

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (Page.IsPostBack) return; 
    DisableControls(); 
} 

private void DisableControls() 
{ 
    lbSelectedDepartmentContacts.Enabled = lbDepartmentContacts.Enabled = false; 
} 
0

通常應該:

似乎是客戶端(至少在寫作的時間)沒有set_enabled()或set_disabled()方法,因此這似乎是不可能的JS,所以你應該與其他答案去它告訴你使用服務器代碼。