2012-09-19 27 views
1

首先,我已經看到了關於此主題的其他線程,並且我只想清除一些被我困住的東西。使用javascript禁用requiredfieldvalidator

我有這個文本框控件和所需的字段校驗:

<td class="style1"> 
    <asp:TextBox runat="server" ID="txtFirstname"></asp:TextBox> 
</td> 
<td> 
    <asp:RequiredFieldValidator ID="rfvFirstname" runat="server" ControlToValidate="txtFirstname" >*</asp:RequiredFieldValidator> 
</td> 

而且這段JavaScript代碼

<script type="text/javascript"> 
    function chkValidators() { 
     alert("enter function chkValidators"); 
     validatorEnable(document.getElementById('<%rfvFirstname%>'), false); 
    } 

這是給我一個編譯錯誤:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1002: ; expected 

Source Error: 

Line 158:   #line default 
Line 159:   #line hidden 
Line 160:   @__w.Write("\'), false);\r\n   }\r\n </script>\r\n"); 
Line 161:  } 
Line 162:   

任何人都知道如何解決這個問題?

尼克

+0

有人知道如何解決這個問題。 ClientID中的 –

回答

3

您是否嘗試過使用..

ValidatorEnable(document.getElementById('<%= rfvFirstname.ClientID %>'), false); 
+0

'd'必須爲大寫。 –

+0

@SidM :: oops。謝謝。 –

+0

'validatorEnable'應該是'ValidatorEnable'(區分大小寫) – jtate

2

我們可以能夠與jQuery的做這樣

$("#ObjectID").removeAttr("data-val-required"); 
0

這裏是我的腳本來禁用驗證並清除Checkbox onclick事件發生錯誤文本。

<script language="javascript" type="text/javascript"> 

     function chktextmiddlenameEnableDisable(obj) { 

      document.getElementById('<%=txtMiddleName.ClientID %>').disabled = obj; 
      if (obj == true) { 
        document.getElementById('<%=RequiredFieldValidator2.ClientID %>').innerHTML = ''; 
        } else { 
           document.getElementById('<%=RequiredFieldValidator2.ClientID %>').innerHTML = 'Please Enter Middle Name'; 
        } 
       } 


</script> 

在我的複選框onclick事件我叫onclick="chktextmiddlenameEnableDisable(this.checked);"

0

這對我的作品時,ValidatorEnable()沒有。

document.getElementById("<%=rfvFirstname.ClientID %>").enabled = false; 
相關問題