Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. custom validator problem

custom validator problem

Scheduled Pinned Locked Moved ASP.NET
helpquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mike Ellison

    Hi Cav. Can you post enough of the code for us to get a better idea of what's happening?

    C Offline
    C Offline
    cavall
    wrote on last edited by
    #3

    OnClick event for the submit button just has a If Page.IsValid then // other code here End this is the Custom Validator Validate event Code (just checking to see if the dropdown is a certain value.. if so, sets the IsValid to T or F): Private Sub cvVendor_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvVendor.ServerValidate If (drpOpCode.SelectedItem.Value = "CORPORATE") OrElse (drpOpCode.SelectedItem.Value = "DIVISION") Then If txtVendor.Text = "" Then args.IsValid = False End If Else args.IsValid = True End If End Sub When I run the program, it never does into this code... cant figure out why... My required field validator will work, but the Custom Validator will not. Skips right over it. Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

    M 1 Reply Last reply
    0
    • C cavall

      OnClick event for the submit button just has a If Page.IsValid then // other code here End this is the Custom Validator Validate event Code (just checking to see if the dropdown is a certain value.. if so, sets the IsValid to T or F): Private Sub cvVendor_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvVendor.ServerValidate If (drpOpCode.SelectedItem.Value = "CORPORATE") OrElse (drpOpCode.SelectedItem.Value = "DIVISION") Then If txtVendor.Text = "" Then args.IsValid = False End If Else args.IsValid = True End If End Sub When I run the program, it never does into this code... cant figure out why... My required field validator will work, but the Custom Validator will not. Skips right over it. Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #4

      Hi Cav. Is it possible you haven't set the ControlToValidate property? Can you list the attribute values at work for this control?

      C 1 Reply Last reply
      0
      • M Mike Ellison

        Hi Cav. Is it possible you haven't set the ControlToValidate property? Can you list the attribute values at work for this control?

        C Offline
        C Offline
        cavall
        wrote on last edited by
        #5

        ID=cvVendor ClientValidationFunction = nothing ControlToValidate = txtVendor 'the textbox Display = Static EnabledClientScript = True Enabled = True EnabledViewState = True need anything else? im developing in VS.net thx "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

        M 1 Reply Last reply
        0
        • C cavall

          ID=cvVendor ClientValidationFunction = nothing ControlToValidate = txtVendor 'the textbox Display = Static EnabledClientScript = True Enabled = True EnabledViewState = True need anything else? im developing in VS.net thx "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #6

          Hmmm... I'm at a loss. I was initially thinking that maybe you needed to set OnServerValidate="cvVendor_ServerValidation" then I noticed you're using the Handles keyword... I'm really not sure why this wouldn't be firing under the circumstances. Do you know for sure the code isn't getting called (i.e. are you using Trace.Write or breakpoints to verify this?) Since you're not using a client validation function, try setting EnableClientScript to false and see if that does anything.

          C 1 Reply Last reply
          0
          • M Mike Ellison

            Hmmm... I'm at a loss. I was initially thinking that maybe you needed to set OnServerValidate="cvVendor_ServerValidation" then I noticed you're using the Handles keyword... I'm really not sure why this wouldn't be firing under the circumstances. Do you know for sure the code isn't getting called (i.e. are you using Trace.Write or breakpoints to verify this?) Since you're not using a client validation function, try setting EnableClientScript to false and see if that does anything.

            C Offline
            C Offline
            cavall
            wrote on last edited by
            #7

            Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

            M C 2 Replies Last reply
            0
            • C cavall

              Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #8

              Yea, the location shouldn't matter. Just for kicks, try setting the OnServerValidate attribute inline within the asp:... tag and remove the Handles keyword from your function. I just read a thread on a google search which sounded very similar to what you're describing; the author indicated the function worked when assigned inline as an attribute but wasn't working otherwise.

              1 Reply Last reply
              0
              • C cavall

                Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                C Offline
                C Offline
                cavall
                wrote on last edited by
                #9

                It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                M D 2 Replies Last reply
                0
                • C cavall

                  It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                  M Offline
                  M Offline
                  Mike Ellison
                  wrote on last edited by
                  #10

                  Perhaps this is a bug?

                  1 Reply Last reply
                  0
                  • C cavall

                    It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                    D Offline
                    D Offline
                    David Flores
                    wrote on last edited by
                    #11

                    It is not a bug. Custom validators when assigned to a text box only go off when there is text in the control. What you want to do is make sure that the ControlToValidate is NOT set. I use custom validators to validate many different controls at once. Also make sure the the button has the CausesValidation property set to true. If you are still having some problems, I can send you my validation code.

                    C 1 Reply Last reply
                    0
                    • D David Flores

                      It is not a bug. Custom validators when assigned to a text box only go off when there is text in the control. What you want to do is make sure that the ControlToValidate is NOT set. I use custom validators to validate many different controls at once. Also make sure the the button has the CausesValidation property set to true. If you are still having some problems, I can send you my validation code.

                      C Offline
                      C Offline
                      cavall
                      wrote on last edited by
                      #12

                      So if I keep the control to Validate NOT set and the Causes Validation set to true, I will then be able to have a conditional statement saying: If X is chosen from the dropdown Then there HAS to be something in the textbox Else it is OK to have nothing in textbox ? Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups