About The Author
Michael Flynn is a Web Developer at Terralever, an interactive marketing agency based in Tempe, AZ. He specializes in web technologies that include C# .NET, SQL, XML, AJAX, jQuery, Flash, and also skills in Photoshop and Illustrator. He was been involved in web development since 1998, and earned a Bachelors and Masters degree in Computer Engineering and Computer Science from the Univerisity of Louisville and holds an MSCT certificate in Web Applications.
Calendar
<<  September 2010  >>
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Validation Summary For Multiple User Controls in C# ASP.NET

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" />

Posted on 9/22/2008 12:44:00 AM by cblaze22

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips | User Controls

Tags: ,

Currently rated 4.0 by 2 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Comments

April 13. 2009 16:30

lokesh

I tried in different ways to give validation summary to my usercontrol textbox but i didn't get what i need correctly
But really sir ur code help me lot and i get what i need its solve big problem in my project
Thank u sir

lokesh in

April 8. 2010 09:59

sunrisedatacare

http://www.sangambayard-c-m.com/

sunrisedatacare in

April 27. 2010 10:56

payday loan advance

This site is a complete internet resource for this. You'll find all you wanted or needed to know, here.

payday loan advance us

Add A Comment




  Country flag