javascript and asp.net validation question

fishjie

Senior member
Apr 22, 2006
234
0
76
www.youtube.com
So here's the scenario. I have a signup form that has a field "email address". I have a web.config switch "requireEmailSignup" that is either true or false. If the switch is true, I want to have client side and server side validation requiring the field to be there. If its false, then I don't want this validation. What's the best practice for doing something like this? Can I use the asp.net requiredfieldvalidator? I'm guessing I'll have to dynamically add the requiredfieldvalidator control in PageInit()?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
The validator controls make it easy to add validation, and they work flexibly on the client and server based on the browser caps, so there's no real reason not to use them. The base validator sports a boolean property... may be called "Validate" or something along those lines... that enables/disables validation on the target control, and you can set that property in your code-behind based on the value in the config.