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. How to bypass fields that have required validation to go to next page

How to bypass fields that have required validation to go to next page

Scheduled Pinned Locked Moved ASP.NET
sysadmintutorialquestion
5 Posts 4 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.
  • B Offline
    B Offline
    Bootzilla33
    wrote on last edited by
    #1

    I want to show required validator when Contract is selected on this toggle.

    <label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
    <label class="switch2">
    <input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/>

    		 </label>
    

    The validation should work for this only when contract is selected:

    <label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>

    	<input class="form-control" id="contractstartdate"  name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
    

    and disabled for this validator:

    <label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
    <%----%>

    			 <input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
    

    The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.

    J B Richard DeemingR 3 Replies Last reply
    0
    • B Bootzilla33

      I want to show required validator when Contract is selected on this toggle.

      <label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
      <label class="switch2">
      <input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/>

      		 </label>
      

      The validation should work for this only when contract is selected:

      <label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>

      	<input class="form-control" id="contractstartdate"  name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
      

      and disabled for this validator:

      <label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
      <%----%>

      			 <input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
      

      The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      I did it using manual validation and jQuery.Validator.js. for MVC I never used the validator for WebForms. But I would remove your validators and go manual. I wrote a jquery script called load_cc_validator and called it when I toggled the form module in jquery. So I wrote the HTML in Razor and manually assigned the values

      Card information

      @Html.Label("Edit_CC_FirstName", "First name on card", new { @class = "control-label" })

          @Html.TextBox("Edit\_CC\_FirstName", "", new { @class = "form-control", data\_val = "true", data\_val\_required = "Card first name required", placeholder = "First name on card" })
          @Html.ValidationMessage("Edit\_CC\_FirstName", new { @class = "field-validation-valid", data\_valmsg\_replace = "true" })
      

      @Html.Hidden("Edit_CC_PaymentID")
      @Html.Hidden("Edit_CC_Brand")
      <button class="btn btn-default btn-lg mobile" type="button" onclick="return editPayment_cancel()">Cancel</button>
       
      <button class="btn checkout pull-right mobile" type="button" onclick="return submit_eCC()">Save</button>

      submit_eCC is just a $ajax call to the controller to update the database, and has nothing to do with validation. editPayment_cancel just clears the form and hides the form module. Since I'm using $ajax, I set the Submit Form Handler to false to not submit a post back of the form. And then wrote the script and called it. This example reflects the whole module, and would take too much time to condense

      function load_eCC_validate() {

      var $cC\_form                    = $("#Edit\_CreditCard"),
          $cC\_location                = $("#Edit\_CC\_LocationName"),
          $cC\_fName                   = $("#Edit\_CC\_FirstName"),
          $cC\_lName                   = $("#Edit\_CC\_LastName"),
          $cC\_code                    = $("#Edit\_CC\_Code"),
          $cC\_phone                   = $("#Edit\_CC\_Phone");
          $bA\_streetAddress1          = $("#Edit\_CC\_StreetAddress1"),
          $bA\_city                    = $("#Edit\_CC\_City"),
          $bA\_stateCode               = $("#Edit\_CC\_StateCode"),
          $bA\_postalCode              = $("#Edit\_CC\_PostalCode"),
          $bA\_countryCode             = $("#Edit\_CC\_CountryCode");
      
      $cC\_form.validate({        
          errorClass: 'form-control input-validation-error',
          validClass: 'form-control',
          errorElement: 'span',
      
      1 Reply Last reply
      0
      • B Bootzilla33

        I want to show required validator when Contract is selected on this toggle.

        <label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
        <label class="switch2">
        <input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/>

        		 </label>
        

        The validation should work for this only when contract is selected:

        <label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>

        	<input class="form-control" id="contractstartdate"  name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
        

        and disabled for this validator:

        <label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
        <%----%>

        			 <input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
        

        The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.

        B Offline
        B Offline
        bVagadishnu
        wrote on last edited by
        #3

        Perhaps Specifying Validation Groups may be what you need? [^]

        _______________________________________________________________ Ah don't lean on me man, cause you can't afford the ticket

        B 1 Reply Last reply
        0
        • B bVagadishnu

          Perhaps Specifying Validation Groups may be what you need? [^]

          _______________________________________________________________ Ah don't lean on me man, cause you can't afford the ticket

          B Offline
          B Offline
          Bootzilla33
          wrote on last edited by
          #4

          ValidationGroup won't work. I only have one button on my form.

          1 Reply Last reply
          0
          • B Bootzilla33

            I want to show required validator when Contract is selected on this toggle.

            <label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
            <label class="switch2">
            <input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/>

            		 </label>
            

            The validation should work for this only when contract is selected:

            <label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>

            	<input class="form-control" id="contractstartdate"  name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
            

            and disabled for this validator:

            <label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
            <%----%>

            			 <input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
            

            The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            The WebForms validators don't include conditional validation out of the box. You can write your own conditional validators, or find a library that does it for you. (The only one I've seen is a commercial component, so I wrote my own.) Or, you can use some code to enable or disable the validator[^] based on a condition. Otherwise, you'll have to stick with the CustomValidator[^]: How to: Validate with a Custom Function for ASP.NET Server Controls[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            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