CustomValidator Returns False, but False is Ignored

Discussion in 'ASP .Net' started by DJ, Dec 21, 2007.

  1. DJ

    DJ Guest

    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.
     
    DJ, Dec 21, 2007
    #1
    1. Advertising

  2. 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.
     
    Mohamad Elarabi [MCPD], Dec 21, 2007
    #2
    1. Advertising

  3. DJ

    bruce barker Guest

    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.
     
    bruce barker, Dec 21, 2007
    #3
  4. DJ

    DJ Guest

    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.
     
    DJ, Dec 27, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jose Fernandez

    CUSTOMVALIDATOR works but page goes on on FALSE

    Jose Fernandez, Jun 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    519
    Peter Blum
    Jun 2, 2005
  2. Jose Fernandez

    CUSTOMVALIDATOR works but page goes on on FALSE

    Jose Fernandez, Jun 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    148
    Jose Fernandez
    Jun 1, 2005
  3. David Thielen

    CustomValidator inside Repeater is ignored

    David Thielen, Oct 23, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    703
    David Thielen
    Oct 23, 2006
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    670
    David A. Black
    Jul 2, 2008
  5. Iñaki Baz Castillo
    Replies:
    9
    Views:
    211
    Igor Pirnovar
    Feb 26, 2009
Loading...

Share This Page