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. Validate textbox with RequiredFieldValidator only if CheckBox is unchecked

Validate textbox with RequiredFieldValidator only if CheckBox is unchecked

Scheduled Pinned Locked Moved ASP.NET
helpquestion
4 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.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.

    N L N 3 Replies Last reply
    0
    • N Naunt

      Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      The ASAP.NET field validaators are run with JavaScript on the client first, then on the server if you have a Server meethod defined. Use some JavaScript to test when you click your submit button, or whatever method you are using to submit the form.

      function ValidatePage()
      {
      return Page_Validate("VALIDATION GROUP NAME");
      }


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • N Naunt

        Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can try using a CustomValidator[^].

        1 Reply Last reply
        0
        • N Naunt

          Please kindly help. I want to validate textbox only if checkbox is unchecked, if checkbox is checked no need to validate textbox as require field. At where and when I have to attach and deattach RequireFieldValidator to textbox? Thanks and best regards.

          N Offline
          N Offline
          Naunt
          wrote on last edited by
          #4

          Thanks Mark Nischalke and Shameel I added a CustomValidator to the textbox and add ClientValidationFunction This is my solution to share with other people those who have problem as mine

          *

          ValidateEmptyText="True" also important here, if not control will not doing validation.

          function CheckPorts(sender, args) {
          var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>')
          if (args.Value == "" && chk.checked == false) {
          args.IsValid = false;
          }
          else {
          args.IsValid = true;
          }
          }

          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