Custom ValidationSummary control with multiple validationgroups in asp.net

I used same logic as described in my previous post.
I made Validate method in custom validationsummary control

public void Validate()
{
RemoveAll();
foreach (string str in this.ValidationGroup.Split(new char[]{',',';'}))
{
ChkControl(str);
}
Page.Validate();
}

protected void ChkControl(string groupName)
{
foreach (IValidator i in Page.GetValidators(groupName))
{
i.Validate();
if (!i.IsValid)
{
DummyValidator dv = new DummyValidator(i.ErrorMessage);
Page.Validators.Add(dv);
m_validators.Add(dv);
}
}
}

ChkControl method creates dummy invalid validators and add them with no validationgroup.

How to use this custom control:
First add it in the toolbox and drag it in your page. Define comma separated multiple validationgroups.
Note: it is based on server side validation so set submit button “Causes validation” property false
And on button click event, call “customcontrolID.Validate()” instead of “Page.validate()” . It uses null validation group so null validationgroup validators are also validated.

Click following to download source code.


Don't forget to say thanks if it helps. :)

No comments:

Post a Comment