Firstly I have seen the other threads on this topic and I just want something cleared up that I am stuck on.
I have this textbox control and required field validator:
<td class="style1">
<asp:TextBox runat="server" ID="txtFirstname"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvFirstname" runat="server" ControlToValidate="txtFirstname" >*</asp:RequiredFieldValidator>
</td>
And this javascript code
<script type="text/javascript">
function chkValidators() {
alert("enter function chkValidators");
validatorEnable(document.getElementById('<%rfvFirstname%>'), false);
}
This is giving me a pilation error:
Description: An error occurred during the pilation 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:
Anyone know how to fix this?
Nick
Firstly I have seen the other threads on this topic and I just want something cleared up that I am stuck on.
I have this textbox control and required field validator:
<td class="style1">
<asp:TextBox runat="server" ID="txtFirstname"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvFirstname" runat="server" ControlToValidate="txtFirstname" >*</asp:RequiredFieldValidator>
</td>
And this javascript code
<script type="text/javascript">
function chkValidators() {
alert("enter function chkValidators");
validatorEnable(document.getElementById('<%rfvFirstname%>'), false);
}
This is giving me a pilation error:
Description: An error occurred during the pilation 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:
Anyone know how to fix this?
Nick
Share Improve this question edited Sep 19, 2012 at 11:04 Sicco 6,2815 gold badges47 silver badges62 bronze badges asked Sep 19, 2012 at 10:52 nick gowdynick gowdy 6,53127 gold badges95 silver badges158 bronze badges 1- Anybody know how to fix this. – nick gowdy Commented Sep 19, 2012 at 11:07
4 Answers
Reset to default 4Have you tried using..
ValidatorEnable(document.getElementById('<%= rfvFirstname.ClientID %>'), false);
We can able to do with jquery like this
$("#ObjectID").removeAttr("data-val-required");
Here is my script to disable validator and clear the error text upon Checkbox onclick event.
<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>
On my check box onclick event I called onclick="chktextmiddlenameEnableDisable(this.checked);"
This works for me when the ValidatorEnable() did not.
document.getElementById("<%=rfvFirstname.ClientID %>").enabled = false;