programmatically set which validation groupS to use

I

ibiza

Hi all,

I have a small question concerning asp.net 2.0 validation groups. I
have this (simplified) situation :

Name Value
_____ _____
|_____| |_____|
_____ _____
|_____| |_____|
_____ _____
|_____| |_____|

So I have 6 textboxes, that goes in pair by row. I'd like the user to
choose whatever boxes he wants to fill, meaning that he can save either
one, two or three name-value pairs. The problem is, a name cannot be
saved without a value and vice-versa. I thought asp.net 2.0 would solve
my validation problems with its new "groups" feature, but I can't
manage how to tell him that "if the user fills one box, the other
besides it must also be filled". I tried many different ways of doing
this, right now I ended with 6 requiredfieldvalidator and textboxes
aside set with the same ValidationGroup, for a total of 3 different
ValidationGroup-s. Can't I programmatically set which ValidationGroup I
want to use just before Page.Validate or anything like this that would
do the job?.....

thanks for your feedback,

ibiza
 
C

Christopher Reed

Try setting the ValidationGroup properties for your respective controls in
the Page_Load method.
 
I

ibiza

How wil this solve my problem? (and would the client validation fail
with your method?)
 
C

Christopher Reed

You set the ValidationGroup properties as you need to in the Page_Load
before the Page_Render so that when you go through validation on your
postback, you have the ValidationGroup properties defined as you want.

If you want to change the ValidationGroup properties on the postback, I
don't believe you can do that because the ValidationGroup property is used
in the rendering step to set up which button will be validated with which
field validator.
 
P

Peter Blum

Validation Groups is not designed for this. It lets a submit control
determine which validators to fire.

You need a way to disable/enable a validator based on the value of something
else on the page. There is no built in feature to do that in ASP.NET on the
validators. You have several options:
1. Post back to the server side to handle validation. (No client-side
validation.) I describe a technique in this article about common issues with
validators: http://aspalliance.com/699.
2. Write javascript code that is called when the value of the textbox
changes, to enable the validator on the client-side. The validation scripts
include this function:
function ValidatorEnable(val, enable)
val - use document.getElementById('ClientID of the validator')
enable - true or false

3. Use my replacement to the ASP.NET Validators, Professional Validation And
More (http://www.peterblum.com/vam/home.aspx). Its 25 validators have this
capability built in. Use the Enabler property to describe the rule that
enables the validator. For more:
http://www.peterblum.com/VAM/DemoEnabler.aspx

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top