Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > CustomValidator Returns False, but False is Ignored

Reply
Thread Tools

CustomValidator Returns False, but False is Ignored

 
 
DJ
Guest
Posts: n/a
 
      12-21-2007
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:

<asp:CustomValidator ID="validCustomDvcPrefix" runat="server"
ClientValidationFunction="validateDvcNum"
Display="None"
ErrorMessage="You provided a device number, but failed to select a
device number prefix."
ValidationGroup="inputDvcLogistic"></asp:CustomValidator>

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.
 
Reply With Quote
 
 
 
 
Mohamad Elarabi [MCPD]
Guest
Posts: n/a
 
      12-21-2007
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:
>
> <asp:CustomValidator ID="validCustomDvcPrefix" runat="server"
> ClientValidationFunction="validateDvcNum"
> Display="None"
> ErrorMessage="You provided a device number, but failed to select a
> device number prefix."
> ValidationGroup="inputDvcLogistic"></asp:CustomValidator>
>
> 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.

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      12-21-2007
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:
>
> <asp:CustomValidator ID="validCustomDvcPrefix" runat="server"
> ClientValidationFunction="validateDvcNum"
> Display="None"
> ErrorMessage="You provided a device number, but failed to select a
> device number prefix."
> ValidationGroup="inputDvcLogistic"></asp:CustomValidator>
>
> 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.

 
Reply With Quote
 
DJ
Guest
Posts: n/a
 
      12-27-2007
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:
> >
> > <asp:CustomValidator ID="validCustomDvcPrefix" runat="server"
> > ClientValidationFunction="validateDvcNum"
> > Display="None"
> > ErrorMessage="You provided a device number, but failed to select a
> > device number prefix."
> > ValidationGroup="inputDvcLogistic"></asp:CustomValidator>
> >
> > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"def nothing=(data) false end" returns 'data' instead of 'false' IƱaki Baz Castillo Ruby 9 02-26-2009 09:38 PM
CustomValidator inside Repeater is ignored David Thielen ASP .Net Web Controls 2 10-23-2006 07:21 PM
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM
CUSTOMVALIDATOR works but page goes on on FALSE Jose Fernandez ASP .Net 1 06-02-2005 04:18 PM
CUSTOMVALIDATOR works but page goes on on FALSE Jose Fernandez ASP .Net Web Controls 0 06-01-2005 10:05 PM



Advertisments