CustomValidator Returns False, but False is Ignored

CustomValidator Returns False, but False is Ignored

am 21.12.2007 09:37:00 von DJ

Having a bit of a problem here, wondering if anyone else has run into this. I
am running two custom validators on a page. The page is used to input/edit
information about devices for the company I work for. Each device may or may
not have a device number associated with it, depending on its phase of
development or deployment. If it does, the device number may have one of many
different prefixes assigned to it, depending on the department.

The first custom validator checks to see if a device prefix has been
selected or if the user indicates there is no number yet. If a prefix is
selected, it checks the textbox that contains the actual number. If the
textbox is empty, it returns an .isValid = false and the validation summary
displays the message. This works just fine.

The second validator checks to see if a number was provided in the textbox.
If yes, then it checks the dropdownlist to see if a prefix was selected. If
not, it returns an .isValid = false to indicate the user has forgotten to
assign a prefix.

Here is the problem. The second custom validator returns a false, but it is
not picked up by the validation summary. I've run the debugger on the script
and know the false is returned. I even put alert windows into the javascript
routine (old school...heh heh) to show the values being returned. The script
functions correctly, but the summary will not pick it up.

Here are the clips from my code:

Custom Validator:

ClientValidationFunction="validateDvcNum"
Display="None"
ErrorMessage="You provided a device number, but failed to select a
device number prefix."
ValidationGroup="inputDvcLogistic">


Javascript Routine validateDvcNum

function validateDvcNum(val, args){
var txtLength = document.getElementById('<%= txtDvcNumber.ClientID
%>').value.length;
if (txtLength > 0){
var selectedValue = document.getElementById('<%=
ddlDvcNumber.ClientID %>').options.value;
if (selectedValue == 7) {
args.isValid = false;
alert(args.isValid + " = false");
} else {
args.isValid = true;
alert(args.isValid + " = true");
}
}
}

In the routine for the var txtLength I've used both the args.Value.length
and the one shown above. Each returns the correct information. I left the
alerts in the code to show what I was talking about. When I select the None
selection in the dropdownlist, the value it returns is 7, which is correct.
Sidenote, I can't combine the validation routines, I need two seperate
validators because I need specific messages based on the checks.

Anyone else seen this before or have any suggestions? Would really
appreciate it!

Thanks in advance.

RE: CustomValidator Returns False, but False is Ignored

am 21.12.2007 11:48:00 von MohamadElarabiMCPD

The Client Custom Validator Handler takes 2 parameters you called them val
and args. The first parameter is actually the Source of the event which is
the customValidator. Not exactly sure that this would work on the client
side but if MS did their homework then you should be able to combine the 2
validators and within your JS function change the error message by changing
val.errorMessage. It is worth a try.

Let me know. Thanks,

--
Mohamad Elarabi
MCP, MCTS, MCPD.


"DJ" wrote:

> Having a bit of a problem here, wondering if anyone else has run into this. I
> am running two custom validators on a page. The page is used to input/edit
> information about devices for the company I work for. Each device may or may
> not have a device number associated with it, depending on its phase of
> development or deployment. If it does, the device number may have one of many
> different prefixes assigned to it, depending on the department.
>
> The first custom validator checks to see if a device prefix has been
> selected or if the user indicates there is no number yet. If a prefix is
> selected, it checks the textbox that contains the actual number. If the
> textbox is empty, it returns an .isValid = false and the validation summary
> displays the message. This works just fine.
>
> The second validator checks to see if a number was provided in the textbox.
> If yes, then it checks the dropdownlist to see if a prefix was selected. If
> not, it returns an .isValid = false to indicate the user has forgotten to
> assign a prefix.
>
> Here is the problem. The second custom validator returns a false, but it is
> not picked up by the validation summary. I've run the debugger on the script
> and know the false is returned. I even put alert windows into the javascript
> routine (old school...heh heh) to show the values being returned. The script
> functions correctly, but the summary will not pick it up.
>
> Here are the clips from my code:
>
> Custom Validator:
>
> > ClientValidationFunction="validateDvcNum"
> Display="None"
> ErrorMessage="You provided a device number, but failed to select a
> device number prefix."
> ValidationGroup="inputDvcLogistic">

>
> Javascript Routine validateDvcNum
>
> function validateDvcNum(val, args){
> var txtLength = document.getElementById('<%= txtDvcNumber.ClientID
> %>').value.length;
> if (txtLength > 0){
> var selectedValue = document.getElementById('<%=
> ddlDvcNumber.ClientID %>').options.value;
> if (selectedValue == 7) {
> args.isValid = false;
> alert(args.isValid + " = false");
> } else {
> args.isValid = true;
> alert(args.isValid + " = true");
> }
> }
> }
>
> In the routine for the var txtLength I've used both the args.Value.length
> and the one shown above. Each returns the correct information. I left the
> alerts in the code to show what I was talking about. When I select the None
> selection in the dropdownlist, the value it returns is 7, which is correct.
> Sidenote, I can't combine the validation routines, I need two seperate
> validators because I need specific messages based on the checks.
>
> Anyone else seen this before or have any suggestions? Would really
> appreciate it!
>
> Thanks in advance.

RE: CustomValidator Returns False, but False is Ignored

am 21.12.2007 17:55:03 von brucebarker

for some obscure reason, the group that wrote the webforms library, unlike
the ajax group, broke with javascript standards and start their property
names with an uppercase letter. so its args.IsValid


-- bruce (sqlwork.com)


"DJ" wrote:

> Having a bit of a problem here, wondering if anyone else has run into this. I
> am running two custom validators on a page. The page is used to input/edit
> information about devices for the company I work for. Each device may or may
> not have a device number associated with it, depending on its phase of
> development or deployment. If it does, the device number may have one of many
> different prefixes assigned to it, depending on the department.
>
> The first custom validator checks to see if a device prefix has been
> selected or if the user indicates there is no number yet. If a prefix is
> selected, it checks the textbox that contains the actual number. If the
> textbox is empty, it returns an .isValid = false and the validation summary
> displays the message. This works just fine.
>
> The second validator checks to see if a number was provided in the textbox.
> If yes, then it checks the dropdownlist to see if a prefix was selected. If
> not, it returns an .isValid = false to indicate the user has forgotten to
> assign a prefix.
>
> Here is the problem. The second custom validator returns a false, but it is
> not picked up by the validation summary. I've run the debugger on the script
> and know the false is returned. I even put alert windows into the javascript
> routine (old school...heh heh) to show the values being returned. The script
> functions correctly, but the summary will not pick it up.
>
> Here are the clips from my code:
>
> Custom Validator:
>
> > ClientValidationFunction="validateDvcNum"
> Display="None"
> ErrorMessage="You provided a device number, but failed to select a
> device number prefix."
> ValidationGroup="inputDvcLogistic">

>
> Javascript Routine validateDvcNum
>
> function validateDvcNum(val, args){
> var txtLength = document.getElementById('<%= txtDvcNumber.ClientID
> %>').value.length;
> if (txtLength > 0){
> var selectedValue = document.getElementById('<%=
> ddlDvcNumber.ClientID %>').options.value;
> if (selectedValue == 7) {
> args.isValid = false;
> alert(args.isValid + " = false");
> } else {
> args.isValid = true;
> alert(args.isValid + " = true");
> }
> }
> }
>
> In the routine for the var txtLength I've used both the args.Value.length
> and the one shown above. Each returns the correct information. I left the
> alerts in the code to show what I was talking about. When I select the None
> selection in the dropdownlist, the value it returns is 7, which is correct.
> Sidenote, I can't combine the validation routines, I need two seperate
> validators because I need specific messages based on the checks.
>
> Anyone else seen this before or have any suggestions? Would really
> appreciate it!
>
> Thanks in advance.

RE: CustomValidator Returns False, but False is Ignored

am 27.12.2007 11:29:00 von DJ

You hit the problem square between the eyes. Many thanks, everything works now.

I did try the .errorMessage along with .ErrorMessage but neither worked.
Too bad, that would have been nice.

Thanks for the solution, appreciate it!

DJ

"bruce barker" wrote:

> for some obscure reason, the group that wrote the webforms library, unlike
> the ajax group, broke with javascript standards and start their property
> names with an uppercase letter. so its args.IsValid
>
>
> -- bruce (sqlwork.com)
>
>
> "DJ" wrote:
>
> > Having a bit of a problem here, wondering if anyone else has run into this. I
> > am running two custom validators on a page. The page is used to input/edit
> > information about devices for the company I work for. Each device may or may
> > not have a device number associated with it, depending on its phase of
> > development or deployment. If it does, the device number may have one of many
> > different prefixes assigned to it, depending on the department.
> >
> > The first custom validator checks to see if a device prefix has been
> > selected or if the user indicates there is no number yet. If a prefix is
> > selected, it checks the textbox that contains the actual number. If the
> > textbox is empty, it returns an .isValid = false and the validation summary
> > displays the message. This works just fine.
> >
> > The second validator checks to see if a number was provided in the textbox.
> > If yes, then it checks the dropdownlist to see if a prefix was selected. If
> > not, it returns an .isValid = false to indicate the user has forgotten to
> > assign a prefix.
> >
> > Here is the problem. The second custom validator returns a false, but it is
> > not picked up by the validation summary. I've run the debugger on the script
> > and know the false is returned. I even put alert windows into the javascript
> > routine (old school...heh heh) to show the values being returned. The script
> > functions correctly, but the summary will not pick it up.
> >
> > Here are the clips from my code:
> >
> > Custom Validator:
> >
> > > > ClientValidationFunction="validateDvcNum"
> > Display="None"
> > ErrorMessage="You provided a device number, but failed to select a
> > device number prefix."
> > ValidationGroup="inputDvcLogistic">

> >
> > Javascript Routine validateDvcNum
> >
> > function validateDvcNum(val, args){
> > var txtLength = document.getElementById('<%= txtDvcNumber.ClientID
> > %>').value.length;
> > if (txtLength > 0){
> > var selectedValue = document.getElementById('<%=
> > ddlDvcNumber.ClientID %>').options.value;
> > if (selectedValue == 7) {
> > args.isValid = false;
> > alert(args.isValid + " = false");
> > } else {
> > args.isValid = true;
> > alert(args.isValid + " = true");
> > }
> > }
> > }
> >
> > In the routine for the var txtLength I've used both the args.Value.length
> > and the one shown above. Each returns the correct information. I left the
> > alerts in the code to show what I was talking about. When I select the None
> > selection in the dropdownlist, the value it returns is 7, which is correct.
> > Sidenote, I can't combine the validation routines, I need two seperate
> > validators because I need specific messages based on the checks.
> >
> > Anyone else seen this before or have any suggestions? Would really
> > appreciate it!
> >
> > Thanks in advance.