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. Odd Custom Validation Problem

Odd Custom Validation Problem

Scheduled Pinned Locked Moved ASP.NET
javascripthelpquestion
2 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.
  • S Offline
    S Offline
    sstocker
    wrote on last edited by
    #1

    I am trying to use custom validation in order to validate certain controls when different radio buttons are checked. There are two radio buttons - when the first one is checked I need to validate location_code and when the second is checked I am going to have to validate four separate textboxes. When the first one is checked, my custom validation is working fine: And here is my javascript function: function location_code(source, args) { if(document.Form1.officelocation[0].checked) { if(args.Value == "select") args.IsValid = false; else args.IsValid = true; } else args.IsValid = true; return; } However, my second custom validator appears to be doing apsolutely nothing. Even when I use the following javascript, nothing happens: function address1(source, args) { alert("hello address"); return; } Does anyone know why my second validator would not be working when it is set up like the first one (which is working)? Does anyone have any other ideas I could possibly use to validate in my situation? Thanks, Scott Stocker

    M 1 Reply Last reply
    0
    • S sstocker

      I am trying to use custom validation in order to validate certain controls when different radio buttons are checked. There are two radio buttons - when the first one is checked I need to validate location_code and when the second is checked I am going to have to validate four separate textboxes. When the first one is checked, my custom validation is working fine: And here is my javascript function: function location_code(source, args) { if(document.Form1.officelocation[0].checked) { if(args.Value == "select") args.IsValid = false; else args.IsValid = true; } else args.IsValid = true; return; } However, my second custom validator appears to be doing apsolutely nothing. Even when I use the following javascript, nothing happens: function address1(source, args) { alert("hello address"); return; } Does anyone know why my second validator would not be working when it is set up like the first one (which is working)? Does anyone have any other ideas I could possibly use to validate in my situation? Thanks, Scott Stocker

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, If the textbox validated by the second custom validator is empty, then the client side function address1 never gets called as it is considered true by default. For more information, you can see CustomValidator Class[^] So in this case, you can use RequiredField Validator instead, however, you are required to provide some script to enable/disable the RequiredField validator depending on the status of the radio buttons as you may not want it to run when the first radio button is selected. Another idea is to develop your own custom validator which accepts an empty textbox to validate. For more information, you can see Developing a Validator Control[^] Just some ideas.

      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