Results 1 to 4 of 4

Thread: custom validator, error isnt added to validation summary?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    custom validator, error isnt added to validation summary?

    I have a custom validator and when an error happens, it doesnt' show up in the validation summary, even though all the other validators show they errors in there.... what do I have to do to add the error to validation summary?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Not sure what your code does but here's an example of a custom validator that shows up in the summary:
    VB Code:
    1. <html>
    2.     <head>
    3.         <script language="javascript">
    4.         function ValidateTextBoxes(s,e)
    5.         {
    6.             var isValid = true;
    7.             var tb1 = document.getElementById("txtTextBox1");
    8.             var tb2 = document.getElementById("txtTextBox2");
    9.             if (s.controltovalidate == "txtTextBox1" && tb2.value.replace(/ /g, "") == "")
    10.                     isValid = false;
    11.             else if (s.controltovalidate == "txtTextBox2" && tb1.value.replace(/ /g, "") == "")
    12.                     isValid = false;
    13.             e.IsValid = isValid;
    14.             return;
    15.         }
    16.         </script>
    17.     </head>
    18.     <body>
    19.         <form runat="server">
    20.        
    21.             <asp:ValidationSummary ID="valSummary" Runat="server"
    22.                 ShowMessageBox="True" ShowSummary="False" DisplayMode="List"/>
    23.                
    24.             <p>Custom validator used to ensure if you enter something in one
    25.             textbox that you must enter sometyhing in the other textbox.</p>
    26.            
    27.             <asp:TextBox ID="txtTextBox1" Runat="server"/><br/>
    28.             <asp:CustomValidator ID="valcustTextBox1" Runat="server"
    29.                 ControlToValidate="txtTextBox1" ClientValidationFunction="ValidateTextBoxes"
    30.                 Display="None" ErrorMessage="Both textboxes must contain values"/>
    31.                
    32.             <asp:TextBox ID="txtTextBox2" Runat="server"/><br/>
    33.             <asp:CustomValidator ID="valcustTextBox2" Runat="server"
    34.                 ControlToValidate="txtTextBox2" ClientValidationFunction="ValidateTextBoxes"
    35.                 Display="None" ErrorMessage="Both textboxes must contain values"/>
    36.            
    37.             <asp:Button ID="btnSubmit" Runat="server" Text="Submit"/>
    38.            
    39.         </form>
    40.     </body>
    41. </html>

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm excuse me if my question is a little stupid

    when I add a custom validator, I can only write the server side code for it.... So basically for writing a client-side code (your jscript code), you just modify the html source manually? or does the ide give you any options to easily write client side code for custom-validation?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    hmmm...I always write my client side code by hand(ie. no IDE short cuts), so i'm not sure if there's an easie way of writing the custom validator jscript functions. I'd think maybe for the pre-canned validators, the IDE would come in handy, but for custom ones it'd be hard for the IDE to guess at your custom validation requirements. So in answer to your question, i just modify the html source manually. BUT i believe there is a way to hook up server side custom event handlers if that's what you're limited to, i just don't remember off the top of my head. I'll keep poking around out of curiousity.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width