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. Validation Issue

Validation Issue

Scheduled Pinned Locked Moved ASP.NET
helphtmlsysadmin
5 Posts 2 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.
  • D Offline
    D Offline
    Dayekh
    wrote on last edited by
    #1

    Hi guys, I have 3 submit buttons on a single page. Each submit button is linked to its controls via a "ValidationGroup". One of the groups even has a Custom Validator. The problem I am having is that the validation is not even firing. I have no idea why. I hope the answer is not silly :( Here is the HTML for ONE of the groups:

    <div id="dvRegistrationValidation" runat="server">
    <asp:RequiredFieldValidator ID="rfvRegistrationCode" ControlToValidate="txtRegistrationCode"
    Display="None" ValidationGroup="RegistrationProcess" ErrorMessage="Registration Code"
    runat="server"></asp:RequiredFieldValidator>
    <asp:CustomValidator ID="cstTarget" runat="server" ErrorMessage="Either Head Office or Farm Site/Unit"
    ValidationGroup="RegistrationProcess" OnServerValidate="cstTarget_ServerValidate"
    Display="None"></asp:CustomValidator>
    <asp:ValidationSummary ID="vsRegistration" runat="server" DisplayMode="BulletList"
    ShowSummary="true" HeaderText="The following fields are mandatory:" ValidationGroup="RegistrationProcess" />
    </div>

    And here is the OnServerValidate Sub Routine:

    Sub cstTarget\_ServerValidate(ByVal source As Object, ByVal e As ServerValidateEventArgs) Handles cstTarget.ServerValidate
    
        If Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = True Then
            e.IsValid = False
        ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = False Then
            e.IsValid = False
        ElseIf Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = False Then
            e.IsValid = True
        ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = True Then
            e.IsValid = True
        End If
    
    End Sub
    

    I appreciate any help given. Thanks!

    D L 2 Replies Last reply
    0
    • D Dayekh

      Hi guys, I have 3 submit buttons on a single page. Each submit button is linked to its controls via a "ValidationGroup". One of the groups even has a Custom Validator. The problem I am having is that the validation is not even firing. I have no idea why. I hope the answer is not silly :( Here is the HTML for ONE of the groups:

      <div id="dvRegistrationValidation" runat="server">
      <asp:RequiredFieldValidator ID="rfvRegistrationCode" ControlToValidate="txtRegistrationCode"
      Display="None" ValidationGroup="RegistrationProcess" ErrorMessage="Registration Code"
      runat="server"></asp:RequiredFieldValidator>
      <asp:CustomValidator ID="cstTarget" runat="server" ErrorMessage="Either Head Office or Farm Site/Unit"
      ValidationGroup="RegistrationProcess" OnServerValidate="cstTarget_ServerValidate"
      Display="None"></asp:CustomValidator>
      <asp:ValidationSummary ID="vsRegistration" runat="server" DisplayMode="BulletList"
      ShowSummary="true" HeaderText="The following fields are mandatory:" ValidationGroup="RegistrationProcess" />
      </div>

      And here is the OnServerValidate Sub Routine:

      Sub cstTarget\_ServerValidate(ByVal source As Object, ByVal e As ServerValidateEventArgs) Handles cstTarget.ServerValidate
      
          If Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = True Then
              e.IsValid = False
          ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = False Then
              e.IsValid = False
          ElseIf Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = False Then
              e.IsValid = True
          ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = True Then
              e.IsValid = True
          End If
      
      End Sub
      

      I appreciate any help given. Thanks!

      D Offline
      D Offline
      Dayekh
      wrote on last edited by
      #2

      Oh dear! I solved it. just for others to know my silly mistake... I need to make the "ValidationGroup" for each button of the each group the same as what was applied in the controls of that group. e.g.

      1 Reply Last reply
      0
      • D Dayekh

        Hi guys, I have 3 submit buttons on a single page. Each submit button is linked to its controls via a "ValidationGroup". One of the groups even has a Custom Validator. The problem I am having is that the validation is not even firing. I have no idea why. I hope the answer is not silly :( Here is the HTML for ONE of the groups:

        <div id="dvRegistrationValidation" runat="server">
        <asp:RequiredFieldValidator ID="rfvRegistrationCode" ControlToValidate="txtRegistrationCode"
        Display="None" ValidationGroup="RegistrationProcess" ErrorMessage="Registration Code"
        runat="server"></asp:RequiredFieldValidator>
        <asp:CustomValidator ID="cstTarget" runat="server" ErrorMessage="Either Head Office or Farm Site/Unit"
        ValidationGroup="RegistrationProcess" OnServerValidate="cstTarget_ServerValidate"
        Display="None"></asp:CustomValidator>
        <asp:ValidationSummary ID="vsRegistration" runat="server" DisplayMode="BulletList"
        ShowSummary="true" HeaderText="The following fields are mandatory:" ValidationGroup="RegistrationProcess" />
        </div>

        And here is the OnServerValidate Sub Routine:

        Sub cstTarget\_ServerValidate(ByVal source As Object, ByVal e As ServerValidateEventArgs) Handles cstTarget.ServerValidate
        
            If Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = True Then
                e.IsValid = False
            ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = False Then
                e.IsValid = False
            ElseIf Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = False Then
                e.IsValid = True
            ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = True Then
                e.IsValid = True
            End If
        
        End Sub
        

        I appreciate any help given. Thanks!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        ... and you could reduce the validate method to a simple

        e.IsValid = Me.chkTarget1.Checked <> Me.chkTarget2.Checked

        :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        D 1 Reply Last reply
        0
        • L Luc Pattyn

          ... and you could reduce the validate method to a simple

          e.IsValid = Me.chkTarget1.Checked <> Me.chkTarget2.Checked

          :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          D Offline
          D Offline
          Dayekh
          wrote on last edited by
          #4

          Thanks for that :)

          L 1 Reply Last reply
          0
          • D Dayekh

            Thanks for that :)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you're welcome. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Prolific encyclopedia fixture proof-reader browser patron addict?
            We all depend on the beast below.


            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