need to have 'validation group'

L

Lloyd Dupont

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...
 
J

Jesse Liberty

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.
 
L

Lloyd Dupont

In ASP.NET 2.0 there are validation groups which do exactly what you want.
Allright...
How does that work?
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
L

Lloyd Dupont

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
 
L

Lloyd Dupont

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>
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top