Groups | Blog | Home
all groups > asp.net > february 2006 >

asp.net : need to have 'validation group'


Jesse Liberty
2/22/2006 9:30:53 AM
In ASP.NET 2.0 there are validation groups which do exactly what you want.
For ASP.NET 1.x you are going to have to be more creative, using custom
validators rather than required field validators.



[quoted text, click to view]

Lloyd Dupont
2/22/2006 10:49:13 PM
On my page the user is ask to set of question.
Say there I have 2 controls like that
== pseudo-C#-code for my control ==
class MyControl : CompositeControl
{
TextBox text;
LinkButton button

override void CreateChildControl()
{
text = new TextBox();
text.ID = "text"
Controls.Add(text);

button = new LinkButton();
buton.Text = submit;
button.Click = HCSubmit;
button.ID = "submit";

// == problem here
RequieredFieldValidator rfv = new RequiredFieldValidator();
rfv.ControlToVerify = "text";
Control.Add(rfv);
}
}
As you could see, text should have some value in it.
Now let's say I have 2 such control on the page and the user fill one and
press the submit link button, it won't be able to submit because the other
field would be empty.
Which is annoying.

Is there a way to limit the scope of the required field validator?
I coukld just remove it, but it provide nice features, so I'm wondering if
there is a solution to this problem, I have heard that ASP.NET 2.0 solve
it...

Lloyd Dupont
2/23/2006 1:15:12 AM
[quoted text, click to view]
Allright...
How does that work?

[quoted text, click to view]

Peter Blum
2/23/2006 11:19:39 AM
Hi Lloyd,

There are a couple of solutions for ASP.NET 1.1:

1. Use server side validation when the page is submitted to fire the
Validate() method of only the desired validators. This article -
http://aspalliance.com/699 - shows you how (along with many other validation
questions). See the topic "Several buttons associated with their own
validators".

2. I built a replacement to the ASP.NET validators that fixes the many
limitations I've found. Its called "Professional Validation And More" (
http://www.peterblum.com/vam/home.aspx ). My validators have validation
groups. You simply assign a group name to the Group property on the submit
button and the associated validators. There are an enormous number of other
improvements I've made to validation and I include a utility to quickly
convert a page from your existing validators to mine.

--- Peter Blum
www.PeterBlum.com
Email: PLBlum@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

[quoted text, click to view]

Lloyd Dupont
2/24/2006 12:00:00 AM
Hi Peter,

Thanks for your links.
Anyway I'm using 2.0 and it's an home project so.. I will certainly go with
build in validation group in 2.0


[quoted text, click to view]

Lloyd Dupont
2/27/2006 12:00:00 AM
As anyone was able to provide the (simple) answer let it be know it is very
simple.
BaseValidator and submiting control (LinkButton, Button, etc...) have a
string ValidationGroup { get; set;}
property.
Just fill it and... Voila!

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
[quoted text, click to view]

AddThis Social Bookmark Button