I have a custom validator on a form, I want to display an error message if a
field is blank OR a dropdown list doesn't have something other than the
default selected. Guess what! If you tell the custom validator to check
the text field and there is nothing in the text field, the validator doesn't
fire! Yeaaaaa, I got hosed by Microsoft stupidity, yeaaaaaa! I can set the
validation control to the dropdown list, but I don't want that because it
does a postback to the server which ends up saving my record. Argh!
Basically, I want the user to type in the text field and be able to press
enter to post the form. If they don't type in the text field then they are
going to select one of the drop down reasons for why they are not typing in
the text field. I tried adding a RequiredField validator but of course that
give me the error when I pick one of the reasons and didn't have anything in
the text field.
So, does anyone know how to make a custom validator that will fire even if
there is nothing in the text field it's validating?
"Johnny Random" <kic...@rabbit.com> wrote in message
news:OHIPxBjOCHA.444@tkmsftngp12...
"Marina" <zlat...@nospam.hotmail.com> wrote in message
news:eVCHTFjOCHA.2512@tkmsftngp10...
The other option is to subclass the CustomValidator and write your own
required event. This could be painful.
Hopefully, by ASP 2.0, they will add an attribute to make these controls
fire when fields are left empty, as well as when they have info in them.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge
****************************************************************************
****
Think outside the box!
****************************************************************************
****
"Johnny Random" <kic...@rabbit.com> wrote in message
news:OHIPxBjOCHA.444@tkmsftngp12...
<asp:CustomValidator id="myValidator"
ControlToValidate="Text1"
ClientValidationFunction="myValidate"
ErrorMessage="even if blank!"
ValidateIfBlank="yes"
runat="server"/>
then in WebUIValidation change
function CustomValidatorEvaluateIsValid(val) {
var value = "";
if (typeof(val.controltovalidate) == "string") {
value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
}
var args = { Value:value, IsValid:true };
if (typeof(val.clientvalidationfunction) == "string") {
eval(val.clientvalidationfunction + "(val, args) ;");
}
return args.IsValid;
}
to something like (air code not tested):
function CustomValidatorEvaluateIsValid(val) {
var value = "";
if (!val.ValidateIfBlank || val.ValidateIfBlank != 'yes')
{
if (typeof(val.controltovalidate) == "string") {
value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
}
}
var args = { Value:value, IsValid:true };
if (typeof(val.clientvalidationfunction) == "string") {
eval(val.clientvalidationfunction + "(val, args) ;");
}
return args.IsValid;
}
-- bruce
"Johnny Random" <kic...@rabbit.com> wrote in message
news:OHIPxBjOCHA.444@tkmsftngp12...
--
Joe //replies to newsgroup only please//
"Johnny Random" <kic...@rabbit.com> wrote in message
news:e$9I2LjOCHA.1996@tkmsftngp12...