I was looking for a simple way to have the convenience of self contained controls, but still use a single validation summary. I created a base class for user controls so code can be reused without repeating it and a property called ValidationGroup that finds all validation controls in the control and assigns the validation group to them.
public class BaseControl : UserControl
{
public BaseControl()
{
}
public virtual string ValidationGroup
{
set
{
foreach (Control control in this.Controls)
{
if (control is BaseValidator)
{
((BaseValidator)control).ValidationGroup = value;
}
}
}
}
}
Below is an example of a validation summary and a user control called address that finds all controls within it to use the validation group of the validation summary.
<asp:ValidationSummary CssClass="validationSummary" runat="server" ID="ValidationSummary"
ValidationGroup="vgEvent" />
<uc:Address ID="CalendarAddress" runat="server" ValidationGroup="vgEvent" />