Validate textbox with RequiredFieldValidator only if CheckBox is unchecked
-
-
Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.
The ASAP.NET field validaators are run with JavaScript on the client first, then on the server if you have a Server meethod defined. Use some JavaScript to test when you click your submit button, or whatever method you are using to submit the form.
function ValidatePage()
{
return Page_Validate("VALIDATION GROUP NAME");
}
I know the language. I've read a book. - _Madmatt
-
Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.
-
Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.
Thanks Mark Nischalke and Shameel I added a CustomValidator to the textbox and add ClientValidationFunction This is my solution to share with other people those who have problem as mine
*
ValidateEmptyText="True" also important here, if not control will not doing validation.
function CheckPorts(sender, args) {
var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>')
if (args.Value == "" && chk.checked == false) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}