Enable and Disable Regular field validation using javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.9.0.min.js"
type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt01" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
ControlToValidate="txt01"
CssClass="val"
EnableClientScript="true"
runat="server"
ErrorMessage="errro"></asp:RequiredFieldValidator>
<asp:Button ID="btnEnable"
CssClass="enb"
runat="server"
Text="Enable
validation" />
<asp:Button ID="btnDisable"
runat="server"
CssClass="Dis"
Text="Disable
Validation" />
<script type="text/javascript">
$(document).ready(function () {
$(document).on('click', '.enb', function ()
{
var vale = $('#<%=RequiredFieldValidator1.ClientID%>')[0];
ValidatorEnable(vale, true);
});
$(document).on('click', '.Dis', function ()
{
var vale = $('#<%=RequiredFieldValidator1.ClientID%>')[0];
ValidatorEnable(vale, false);
});
});
function Testing() {
var test = $('.cls');
try {
ValidatorEnable(test, false);
}
catch (err) {
alert('Oops');
}
}
</script>
</div>
</form>
</body>
</html>
If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)
No comments:
Post a Comment