I do exactly this all the time with ValidationSummary and the various
Validation controls. I hope that this gets you started:
<%@ Control Language="c#" Codebehind="____.ascx.cs"
AutoEventWireup="false" Inherits="______" %>
....
<tr><td class="RequiredField">*Name
<asp:RequiredFieldValidator
ControlToValidate="tbName"
Display="Static"
ErrorMessage="Enter the Name"
EnableClientScript="False"
runat="server">
<img src='/images/common/WarningIcon.gif'>
</asp:RequiredFieldValidator>
</td><td><asp:TextBox id="tbName" runat="Server" MaxLength="100"/></td></tr>
<tr><td align="center" colspan="2">
<!-- Validation summary -->
<asp:ValidationSummary
DisplayMode="BulletList"
Align="Center" Class="FormErrors"
runat="server"
HeaderText="Correct the following errors"
ForeColor="White"/>
</td></tr>
A couple of things to note:
1. You should set the ErrorMessage property of your Validation control,
such as what I've done
2. You can also specify a static body which will be displayed at the
location that you wish. In the RequiredFieldValidator example above, the
WarningIcon.gif will display if the validation control determines that
there's an error
3. Display="Static" means that the .NET framework will allocate space on
the page for the warning icon image even though it is not displayed, so
that, when it is actually displayed it does not alter the page layout in
any way (it seems at least)
3. Note that the ValidationSummary control has a Class attribute. Here
is my CSS for that. The CSS is not cleaned up, but in any case it
renders all error text in bold white, with a bright red background.
Perfect for those colour blind people

:
..FormErrors {
Color: white;
Background: red;
Font-Family: Arial, Helvetica, sans-serif;
FONT-SIZE: 9pt;
Font-Weight: bold;
}
..FormErrors ul {
Padding: 0;
Margin: 0;
Color: white;
Font-weight: bold;
List-Style: disc;
List-Style-Position: inside;
Border: none;
}
..MainBody .FormErrors ul li {
Color: white;
}
Shan Plourde
Ed said:
Ken,
Thanks for the response.
No, it does not do what I want, it displays the names of the fields in
the ValidationSummary. I want it just to say "The fields in red are
required". Also, a RequiredFieldValidator does not do exactly what I
want either. I just want to change the label in front of the input
field to red, instead of having a separate space to display the error
message. Is there a way to do this or do I need a label and then the
required field validator which shows an error message?
Any ideas?
right now I put my own validation in Form_Load when IsPostBack is
true. I check the value of each textbox, if it is empty then i change
the cssClass of the label in front (to red text), and then change the
label at the top to "The following fields in red are required".
thanks,
-ed
Hi Ed,
Wouldn't the ValidationSummary control do what you need?
<asp:ValidationSummary id="ValidationSummary1" runat="server"
DisplayMode="SingleParagraph" HeaderText="The following fields in red
are required"></asp:ValidationSummary></P>
Ken
Microsoft MVP [ASP.NET]
Hello,
I have a simple form with some input boxes. After validation if one
fails, then I would like to at the top of the page say something
like "The following fields in red are required" and then change the
label in front of the textbox or dropdown list to red... is this
possible with asp.net? It seems you can only put a
RequiredFieldValidator on the page, and if it fails validation then
that text is displayed... ?
Thanks
-ed