Validation By Control ASP.Net

<%@ Page Language="C#" %>

    void Page_PreRender()
    {
        foreach (BaseValidator valControl in Page.Validators)
        {
            WebControl assControl = (WebControl)Page.FindControl(valControl.ControlToValidate);
            if (!valControl.IsValid)
                assControl.BackColor = System.Drawing.Color.Yellow;
            else
                assControl.BackColor = System.Drawing.Color.White;
        }
    }



    Show Validators


    
    

        
            id="lblFirstName"
        Text="First Name"
        AssociatedControlID="txtFirstName"
        Runat="server" />
        
            id="txtFirstName"
        Runat="server" />
            id="reqFirstName"
        ControlToValidate="txtFirstName"
        Text="(Required)"
        EnableClientScript="false"
        Runat="server" />   
     
    
        
            id="lblLastName"
        Text="Last Name"
        AssociatedControlID="txtLastName"
        Runat="server" />
        
            id="txtLastname"
        Runat="server" />
            id="reqLastName"
        ControlToValidate="txtLastName"
        Text="(Required)" 
        EnableClientScript="false"
        Runat="server" />   
     
     
     
             id="btnSubmit"
        Text="Submit"
        Runat="server" />