Custom Validation based on RadioButtonList selection

Last post 08-14-2007 6:04 PM by shalan99. 3 replies.

Sort Posts:

  • Custom Validation based on RadioButtonList selection

    08-01-2007, 4:32 PM
    • Loading...
    • shalan99
    • Joined on 04-15-2007, 8:03 PM
    • Posts 99

    Hi everyone,

    I have a RadioButtonList with 3 listItems (One, Two & Three), as well as 3 texboxes.  What happens is when I select "One" from RadioButtonList then only the first textbox displays, if I select "Two" then the first and second textboxes show.....and so on.

    I have required-field & regular-expression validators on all textboxes, but what is happening, is that I only want validation to fire for the first textbox if it is visible, and for the first and second textboxes if they are both visible...and so on.

    please could someone help me out on this one?  I imagine I would need some Javascript function to do this, but its been a while since I did any JS validation, and I have no idea where to start!

     

    Much thanx & kind regards

    Shalan99
     

  • Re: Custom Validation based on RadioButtonList selection

    08-01-2007, 4:39 PM
    Answer
    • Loading...
    • Freakyuno
    • Joined on 01-20-2005, 4:57 PM
    • Midwest - United States
    • Posts 1,952
    • Moderator
      TrustedFriends-MVPs

    .NET custom validators in Framework 2.0 have two components,  Server side validation, and client side validation.  I'm by no means a guru when it comes to client side validation - because me and JavaScript dont get along, but it's pretty easy once you get to the server...and you could incorporate a few different methods.

    1.)  Because you know the textboxes are in direct relation to the radio buttons.  Check to see which radio button is selected and use a CASE statment to perform validation based on which textboxes are showing.  You'd do this inside a custom validator. 

    2.) You can easily - inside a custom validator check the visible state of the checkbox, to determine if you should validate it.  If textbox1.visible then -> Valdate -> Else -> Move on

    3.) Add the controls and validators dynamically, so that the textboxes you dont want to validate are truly not even on the page when the validation fires.  This is the hardest method, but also the most flexible because you havent hard coded the amount, nor the id of the textboxes anywhere for validation purposes.

     

  • Re: Custom Validation based on RadioButtonList selection

    08-01-2007, 6:34 PM
    Answer
    • Loading...
    • PLBlum
    • Joined on 06-28-2002, 9:20 AM
    • Boston, MA
    • Posts 5,155
    • TrustedFriends-MVPs

    Let me direct you to a resource since this is pretty tricky. I recently released a free video training on validation which includes how to selectively enable a validator.

    http://www.peterblum.com/dnrtv.aspx

    In addition, check out my article on validation: http://aspalliance.com/699.

    Finally, you can replace the ASP.NET validators with my commercial ones and get this capability built in. All of my 25 validators have a property called Enabler where you define the rule that enables and disables it on-the-fly.

    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: Custom Validation based on RadioButtonList selection

    08-14-2007, 6:04 PM
    • Loading...
    • shalan99
    • Joined on 04-15-2007, 8:03 PM
    • Posts 99

    Hi guys,

    Sorry for the delayed reply, been busy with a Go-live project that has kept me on my toes!  Thanks alot for the suggestions, but thank u Peter...the article and the video cleared alot of things up for me.  Also, using a radiolist control seemed to have made things easier!

    regards
    Shalan99

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter