I have custom application page, and I need some custom client side validation. After spending hours on trying to make asp.net CustomValidator to work, I googled a lil bit and found few posts, that advise to use InputFormCustomValidator, instead of asp.net based CustomValidator. From what I see there is no big difference between two controls ( well maybe 2 or 3 additional properties that InputFormCustomValidator supports ).
I have a textbox, and jQuery datepicker, when user clicks on submit button I just want to check what option is selected on the dropdownlist on the form, and than based on the selected value, I need to check if textbox has any input. This is what I have so far.
<asp:TextBox ID="txtProjectStartDate" runat="server" Width="75" />
<SharePoint:InputFormCustomValidator ID="InputFormCustomValidator1" runat="server" ControlToValidate="txtProjectStartDate"
ClientValidationFunction="ValidateProjectStartDate" ErrorMessage="*" EnableClientScript="true" />
and this is custom validation function
function ValidateProjectStartDate(sender, args) {
var projectType = $('select[id*=ddlProjectType]').val();
if (parseInt(projectType) != 1) {
var startDate = $('input[type=text][id*=txtProjectStartDate]').val();
if (startDate.length == 0) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}
I have checked, there is no js error on my page, but custom validator doesn't fire. I have even tried to handle submit button click event, and programmatically force Validation, but no luck so far. If you've successfully used asp.net CustomValidator control in similar scenarios, I'd be glad to switch to CustomValidator as well.
Can anybody help me to make this code work ?