Hello - I'm an ASP 3.0 person who's new to .NET and I'm trying to figure out how to do something I do in ASP.
I would like to validate a textbox for 2 conditions: Is textbox empty / null and is the string length over 30 chars.
In ASP, I'd do it like this (using 2 custom functions):
Ok -
So here's my question:
Can I take advantage of the CustomValidator control to do this exact thing w/ some additional goodness??
The problem I'm having with the CustomValidator control is that the ErrorMessage thing seems to be hard coded. I would like to use my Serverside ValidationFunction to set the error message that is displayed, but it seems I can only have one message.
I hope I'm asking this clear enough.
It seems to me that I would have to add 2 custom validators to check for 2 conditions and have 2 error messages. I would like to have only 1 custom validator for one control that validates for 2 conditions and changes the ErrorMessage to display which conditions were not met.
Thanks again - let me know if you need clarification..
I would like to validate a textbox for 2 conditions: Is textbox empty / null and is the string length over 30 chars.
In ASP, I'd do it like this (using 2 custom functions):
Code:
If IsBlank(request.form("myTextbox")) then
ErrMsg = ErrMsg & "Blah is a required field and cannot be left blank."
End If
If ValidLength(request.form("myTextbox"), 30)
ErrMsg = ErrMsg & "Blah is a cannot exceed 30 characters."
End If
If ErrMsg <> "" then
' It failed validation - write out ErrMsg
Else
' Passed validation - do stuff
End If
Ok -
So here's my question:
Can I take advantage of the CustomValidator control to do this exact thing w/ some additional goodness??
The problem I'm having with the CustomValidator control is that the ErrorMessage thing seems to be hard coded. I would like to use my Serverside ValidationFunction to set the error message that is displayed, but it seems I can only have one message.
I hope I'm asking this clear enough.
It seems to me that I would have to add 2 custom validators to check for 2 conditions and have 2 error messages. I would like to have only 1 custom validator for one control that validates for 2 conditions and changes the ErrorMessage to display which conditions were not met.
Thanks again - let me know if you need clarification..