custom validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Slim

    custom validation

    I cant seem to get my custom validation to work. can anyone spot where i
    have gone wrong

    control
    <asp:CustomVali dator ID="checkHandic ap" runat="server"
    ControlToValida te="startHandic ap" ErrorMessage="H andicap out of range"
    OnServerValidat e="checkHandica p_ServerValidat e" ></asp:CustomValid ator>



    code behind


    Protected Sub checkHandicap_S erverValidate(B yVal source As Object, ByVal
    args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles
    checkHandicap.S erverValidate

    Dim ans As Integer = Integer.Parse(a rgs.Value)

    Try

    If ans -27 And ans <= 27 Then

    args.IsValid = True

    Exit Sub

    End If

    Catch exc As Exception

    End Try

    args.IsValid = False

    End Sub






  • Dblood

    #2
    Re: custom validation

    Slim,

    Are you getting an error message? What values are failing? I mocked up
    an example using your code, but don't know how it's failing for you so
    I don't really know how to help.

    dkb

    Comment

    • Slim

      #3
      Re: custom validation

      I get no error, but I get no return either,

      from what tests I could do, the function was not firing



      "Dblood" <dbloodworth@in finitechs.comwr ote in message
      news:1155912066 .097764.223430@ i42g2000cwa.goo glegroups.com.. .
      Slim,
      >
      Are you getting an error message? What values are failing? I mocked up
      an example using your code, but don't know how it's failing for you so
      I don't really know how to help.
      >
      dkb
      >

      Comment

      • Dblood

        #4
        Re: custom validation

        Slim,

        On the mockup I created, the event fired, and your code worked. I
        don't see a reason why it would not work. I copied your control
        declaration from the post, copied the code from the post. I dumped them
        into a page, added the withevents declaration of the checkhandicap
        variable, added a button (so that I could have the page postback) and
        it worked.

        There must be more to the problem. What is causing postback in your
        app? Can you set a breakpoint, then run in debug and verify that the
        checkHandicap_S erverValidate Sub is not being called? If not, add a
        "response.write (args.IsValid)" at each of the conditions (where
        args.IsValid is set to true or false) to ensure that the app is calling
        the sub.

        This is a weird one,

        dkb

        Comment

        • Slim

          #5
          Re: custom validation


          "Dblood" <dbloodworth@in finitechs.comwr ote in message
          news:1155915717 .498238.77070@m 79g2000cwm.goog legroups.com...
          Slim,
          >
          On the mockup I created, the event fired, and your code worked. I
          don't see a reason why it would not work. I copied your control
          declaration from the post, copied the code from the post. I dumped them
          into a page, added the withevents declaration of the checkhandicap
          variable,
          where do i put the with events?


          added a button (so that I could have the page postback) and
          it worked.
          >
          There must be more to the problem. What is causing postback in your
          app? Can you set a breakpoint, then run in debug and verify that the
          checkHandicap_S erverValidate Sub is not being called? If not, add a
          "response.write (args.IsValid)" at each of the conditions (where
          args.IsValid is set to true or false) to ensure that the app is calling
          the sub.
          >
          This is a weird one,
          >
          dkb
          >

          Comment

          • Dblood

            #6
            Re: custom validation

            What I mean is that when I copied your control (the text below) to an
            aspx page, it didn't create the variable for me on the code-behind
            page.

            <asp:CustomVali dator ID="checkHandic ap" runat="server"
            ControlToValida te="startHandic ap" ErrorMessage="H andicap out of range"
            OnServerValidat e="checkHandica p_ServerValidat e"></asp:CustomValid ator>

            So, I had to create that variable myself. Yours is probably already
            there. Near the top of the code-behind view you'll see:

            Protected WithEvents checkHandicap As CustomValidator

            Any luck using the Response.write to see if the isvalid ever changes?
            Can you debug the project and step through to see if the event is
            firing?

            dkb

            Comment

            • Slim

              #7
              Re: custom validation

              No the response.write is not returning anything

              and no where on my page or code behind is a WithEvents statement


              "Dblood" <dbloodworth@in finitechs.comwr ote in message
              news:1155931352 .939942.45630@7 4g2000cwt.googl egroups.com...
              What I mean is that when I copied your control (the text below) to an
              aspx page, it didn't create the variable for me on the code-behind
              page.
              >
              <asp:CustomVali dator ID="checkHandic ap" runat="server"
              ControlToValida te="startHandic ap" ErrorMessage="H andicap out of range"
              OnServerValidat e="checkHandica p_ServerValidat e"></asp:CustomValid ator>
              >
              So, I had to create that variable myself. Yours is probably already
              there. Near the top of the code-behind view you'll see:
              >
              Protected WithEvents checkHandicap As CustomValidator
              >
              Any luck using the Response.write to see if the isvalid ever changes?
              Can you debug the project and step through to see if the event is
              firing?
              >
              dkb
              >

              Comment

              • Dblood

                #8
                Re: custom validation

                Slim,

                Add this to your code behind then,

                Protected WithEvents checkHandicap As _
                System.Web.UI.W ebControls.Cust omValidator


                and then try again.

                dkb

                Comment

                • Kronzucker

                  #9
                  Re: custom validation


                  Dblood schrieb:
                  Slim,
                  >
                  Add this to your code behind then,
                  >
                  Protected WithEvents checkHandicap As _
                  System.Web.UI.W ebControls.Cust omValidator
                  >
                  >
                  and then try again.
                  >
                  dkb

                  Hey Slim. If I understand you right, I had the same problem some time
                  ago on the client side. In my case args.Value didn't return anything.
                  The event was fired, but arg.Value was empty.

                  My solution was to adress the textbox directly throug something like:
                  ((TextBox)Page. FindControl("st artHandicap")). Text

                  MfG
                  Georg Fleischer

                  Comment

                  • Slim

                    #10
                    Re: custom validation


                    "Dblood" <dbloodworth@in finitechs.comwr ote in message
                    news:1156166951 .711057.213590@ p79g2000cwp.goo glegroups.com.. .
                    Slim,
                    >
                    Add this to your code behind then,
                    >
                    Protected WithEvents checkHandicap As _
                    System.Web.UI.W ebControls.Cust omValidator
                    >
                    >
                    and then try again.
                    >
                    sorry took so long to reply

                    It tells me that it is already declared with events, yet its not on the
                    page.

                    I assume that VS2005 hides it from view.

                    dkb
                    >

                    Comment

                    • Slim

                      #11
                      Re: custom validation

                      I have since found that no events are working in the site except for page
                      load, they were working until recently?



                      "Slim" <me@here.comwro te in message
                      news:eTM5iW4xGH A.4092@TK2MSFTN GP04.phx.gbl...
                      >
                      "Dblood" <dbloodworth@in finitechs.comwr ote in message
                      news:1156166951 .711057.213590@ p79g2000cwp.goo glegroups.com.. .
                      >Slim,
                      >>
                      >Add this to your code behind then,
                      >>
                      >Protected WithEvents checkHandicap As _
                      >System.Web.UI. WebControls.Cus tomValidator
                      >>
                      >>
                      >and then try again.
                      >>
                      >
                      sorry took so long to reply
                      >
                      It tells me that it is already declared with events, yet its not on the
                      page.
                      >
                      I assume that VS2005 hides it from view.
                      >
                      >
                      >dkb
                      >>
                      >
                      >

                      Comment

                      • seigo

                        #12
                        Re: custom validation

                        Hi Slim,

                        Try to add ValidateEmptyTe xt="true" to your custom validator.
                        For more details read
                        http://msdn2.microsoft.com/en-us/lib...emptytext.aspx.

                        Regards,
                        Alex.

                        Slim wrote:
                        I cant seem to get my custom validation to work. can anyone spot where i
                        have gone wrong
                        >
                        control
                        <asp:CustomVali dator ID="checkHandic ap" runat="server"
                        ControlToValida te="startHandic ap" ErrorMessage="H andicap out of range"
                        OnServerValidat e="checkHandica p_ServerValidat e" ></asp:CustomValid ator>
                        >
                        >
                        >
                        code behind
                        >
                        >
                        Protected Sub checkHandicap_S erverValidate(B yVal source As Object, ByVal
                        args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles
                        checkHandicap.S erverValidate
                        >
                        Dim ans As Integer = Integer.Parse(a rgs.Value)
                        >
                        Try
                        >
                        If ans -27 And ans <= 27 Then
                        >
                        args.IsValid = True
                        >
                        Exit Sub
                        >
                        End If
                        >
                        Catch exc As Exception
                        >
                        End Try
                        >
                        args.IsValid = False
                        >
                        End Sub

                        Comment

                        • Slim

                          #13
                          Re: custom validation


                          "seigo" <seigo.ua@gmail .comwrote in message
                          news:1156433231 .453148.222040@ p79g2000cwp.goo glegroups.com.. .
                          Hi Slim,
                          >
                          Try to add ValidateEmptyTe xt="true" to your custom validator.
                          thanks but no go
                          For more details read
                          http://msdn2.microsoft.com/en-us/lib...emptytext.aspx.
                          >
                          Regards,
                          Alex.
                          >
                          Slim wrote:
                          >I cant seem to get my custom validation to work. can anyone spot where i
                          >have gone wrong
                          >>
                          >control
                          ><asp:CustomVal idator ID="checkHandic ap" runat="server"
                          >ControlToValid ate="startHandi cap" ErrorMessage="H andicap out of range"
                          >OnServerValida te="checkHandic ap_ServerValida te" ></asp:CustomValid ator>
                          >>
                          >>
                          >>
                          >code behind
                          >>
                          >>
                          >Protected Sub checkHandicap_S erverValidate(B yVal source As Object, ByVal
                          >args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles
                          >checkHandicap. ServerValidate
                          >>
                          >Dim ans As Integer = Integer.Parse(a rgs.Value)
                          >>
                          >Try
                          >>
                          >If ans -27 And ans <= 27 Then
                          >>
                          >args.IsValid = True
                          >>
                          >Exit Sub
                          >>
                          >End If
                          >>
                          >Catch exc As Exception
                          >>
                          >End Try
                          >>
                          >args.IsValid = False
                          >>
                          >End Sub
                          >

                          Comment

                          • Slim

                            #14
                            Re: custom validation


                            "Slim" <me@here.comwro te in message
                            news:OOANjA5xGH A.4024@TK2MSFTN GP02.phx.gbl...
                            >I have since found that no events are working in the site except for page
                            >load, they were working until recently?
                            sorry false alarm, its only that page, event a simple button on click event
                            will not work on the page.

                            I have recreated a new page with new code behind page, and when I copy html
                            and controls I have the same problems


                            >
                            >
                            >
                            "Slim" <me@here.comwro te in message
                            news:eTM5iW4xGH A.4092@TK2MSFTN GP04.phx.gbl...
                            >>
                            >"Dblood" <dbloodworth@in finitechs.comwr ote in message
                            >news:115616695 1.711057.213590 @p79g2000cwp.go oglegroups.com. ..
                            >>Slim,
                            >>>
                            >>Add this to your code behind then,
                            >>>
                            >>Protected WithEvents checkHandicap As _
                            >>System.Web.UI .WebControls.Cu stomValidator
                            >>>
                            >>>
                            >>and then try again.
                            >>>
                            >>
                            >sorry took so long to reply
                            >>
                            >It tells me that it is already declared with events, yet its not on the
                            >page.
                            >>
                            >I assume that VS2005 hides it from view.
                            >>
                            >>
                            >>dkb
                            >>>
                            >>
                            >>
                            >
                            >

                            Comment

                            • Slim

                              #15
                              Re: custom validation

                              Sorry to waste your time

                              I found that I had to make sure the all other required validation controls
                              were satisfied before custom validation would work.

                              after pulling my hair out for days, I calmed down took a deep breath and had
                              a logical look at my code,

                              thanks for your time

                              "Slim" <me@here.comwro te in message
                              news:ev$3pU5xGH A.1252@TK2MSFTN GP04.phx.gbl...
                              >
                              "Slim" <me@here.comwro te in message
                              news:OOANjA5xGH A.4024@TK2MSFTN GP02.phx.gbl...
                              >>I have since found that no events are working in the site except for page
                              >>load, they were working until recently?
                              >
                              sorry false alarm, its only that page, event a simple button on click
                              event will not work on the page.
                              >
                              I have recreated a new page with new code behind page, and when I copy
                              html and controls I have the same problems
                              >
                              >
                              >
                              >>
                              >>
                              >>
                              >"Slim" <me@here.comwro te in message
                              >news:eTM5iW4xG HA.4092@TK2MSFT NGP04.phx.gbl.. .
                              >>>
                              >>"Dblood" <dbloodworth@in finitechs.comwr ote in message
                              >>news:11561669 51.711057.21359 0@p79g2000cwp.g ooglegroups.com ...
                              >>>Slim,
                              >>>>
                              >>>Add this to your code behind then,
                              >>>>
                              >>>Protected WithEvents checkHandicap As _
                              >>>System.Web.U I.WebControls.C ustomValidator
                              >>>>
                              >>>>
                              >>>and then try again.
                              >>>>
                              >>>
                              >>sorry took so long to reply
                              >>>
                              >>It tells me that it is already declared with events, yet its not on the
                              >>page.
                              >>>
                              >>I assume that VS2005 hides it from view.
                              >>>
                              >>>
                              >>>dkb
                              >>>>
                              >>>
                              >>>
                              >>
                              >>
                              >
                              >

                              Comment

                              Working...