Question about validators

  • Thread starter Thread starter angus
  • Start date Start date
A

angus

Dear all,

I have 5 textboxes, and 2 buttons in a webform.

1-3 textboxes would be validated by 3 Required Field Validators if button 1
is click;
4-5 textboxes would be validated by 2 Required Field Validators if button 2
is click.

I have found whether i click button 1 or button 2, textboxes 1-5 will be
validated.

What can i do if i want to validate those textboxes separately.

Thank you.

Regards,
Angus
 
angus said:
Dear all,

I have 5 textboxes, and 2 buttons in a webform.

1-3 textboxes would be validated by 3 Required Field Validators if button 1
is click;
4-5 textboxes would be validated by 2 Required Field Validators if button 2
is click.

I have found whether i click button 1 or button 2, textboxes 1-5 will be
validated.

What can i do if i want to validate those textboxes separately.

Thank you.

Regards,
Angus

1) wait for Whidbey, which apparently has validator groups
2) use (server-side) custom validators, maybe this will work:
- two custom validators, one for each group of textboxes. they check
if every textbox in it's group is non-empty
- in the onclick event, do not check Page.IsValid, but check
the specific validator (set the other to "valid")


Hans Kesting
 
Hi angus
The validators that come with .net don't do this
I've developed a set of validator controls that allow you to group them into
logical forms.

e.g.
<extendedvalidators:RequiredFieldValidator id="RequiredFieldValidator2"
runat="server" ErrorMessage="type something" ControlToValidate="TextBox1"
group="1"></extendedvalidators:RequiredFieldValidator>

In the future I'd like to sell them (after a bit more testing). So far a
couple of people who have posted similar questions have found that they
work.
If you like to try them mail me at (e-mail address removed) and I'll send
you the dll, let me know if you are using visual studio version 2002 or 2003
Cheers
Joe Gass
MCSD.net
 
Angus,

I'm not sure what Hans and Joe Gass are meaning when they say you can't do
this. Maybe I'm not understanding your question, but I have no problem
setting the Enable and Visible properties of RequiredFieldValidators to
false or true and only firing off the ones I need given a particular
scenario, such as clicking button 1 or button 2. I've been doing my app
this way for almost 2 years now. You might give that a try.

I'm sorry if I am misunderstanding your question and giving you an erroneous
answer for your situation.

HTH,

Raymond Lewallen
 
Raymond, I think you are talking about setting the enabled or visible
properties off on the server side.
If you use client side validation with the regular .net validators all the
validators fire when a button with causesValidation set to true is pressed.
 
Joe, you are correct. I am changing those server side. Can he set
causesValidation to False on the button, and then on the click event handler
sub for the button, enable or disable the validators he needs fired and then
call Page.IsValid? Its been a long while since I've looked at my code that
does that, but I think that is how I handle it for those types of scenarios.

Thanks for your clarification,

Raymond Lewallen
 
Check out my post in the thread 'validating portions of asp.net page' on Jan
5.
It might be what you are looking for.
 
The concept you are looking for is "validation groups". It has been
identified in several forms in this thread.
- ASP.NET 2.0
- Joe Gass's future product

There are several shipping products that replace Microsoft's validators with
support for validation groups. Mine is "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx. It overcomes the limitations of
Microsoft's validators. Those limitations are covered here:
http://www.peterblum.com/vam/valmain.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
 
Back
Top