473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

RequiredFieldValidator - changing font color of label?

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
Nov 18 '05 #1
7 8880
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]

"Ed West" <We**@westlake.com> wrote in message
news:uD****************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #2

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
Ken Cox [Microsoft MVP] wrote:
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]

"Ed West" <We**@westlake.com> wrote in message
news:uD****************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #3
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 :P :

..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 West wrote:

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
Ken Cox [Microsoft MVP] wrote:
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]

"Ed West" <We**@westlake.com> wrote in message
news:uD****************@tk2msftngp13.phx.gbl...
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



Nov 18 '05 #4
Hi Ed,

I rewrote ASP.NET validation to do a lot more than what Microsoft ships.
With "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx), you can do exactly what you
described: setting the label to a different color and showing a hint at the
top to tell what to do. Download the free trial version to look at it. Here
are the specifics of how to do this:

1. Hide the RequiredTextValidator by setting the Display property to None in
the ErrorFormatter property. (You can do something similar with MS
Validators.)
2. Add my ValidationSummary control. Set the HeaderText to "The fields in
red are required". Set the DisplayMode property to "None". This will make it
only show the HeaderText.
3. On the RequiredTextValidator, use the HiliteFields property to identify
the associated Label control that you want to turn red. Follow the steps on
page 95 of the User's Guide to establish the style sheet that will be
applied to the Label.

The HiliteFields feature is only one of the ways to get the user's attention
Professional Validation And More. You can also:
* Set focus to the field with error
* Show an alert when the user enters an error
* Change the style of the field with the error itself
* Show a small image that takes up very little screen room. You can either
have it popup an alert or a tooltip with the error message. You can even
have it blink the image.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Ed West" <We**@westlake.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...

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
Ken Cox [Microsoft MVP] wrote:
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]

"Ed West" <We**@westlake.com> wrote in message
news:uD****************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #5

Hi Shan,

thanks for the reply but your example does not do what I was asking

(1) The validation summary lists the offending fields. I do not want
the offending fields listed there.

(2) I want the offending field's font color to change. All you are
doing is adding a warning box.

Is there any way to do this without writing code? (Not that I mind, but
I would like to use Microsoft's built in stufff, but once again it looks
like it is useless) Or do I have to buy that guy who posted's component?

thanks

-dan


Shan Plourde wrote:
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 :P :

.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 West wrote:

Nov 18 '05 #6
Yes you're right, I am doing 2 things in my example:
1. Listing the offending fields
2. Displaying an image next to the label (a warning icon image) which
makes the label stand out on the page

So my approach is different from what you're trying to do. Out of the
box I don't think you can do this without writing code. You could
possibly extend the existing validation/UI model, perhaps such as:
<RequiredFieldValidator
ValidationLabel="<your label name>"
ValidationLabelStyle="<your style>"
/RequiredFieldValidator>

This way you would not have to then do any programmatic intervention. Of
course, you can always buy that other guys stuff if that's too much work :P

Shan Plourde
Ed West wrote:

Hi Shan,

thanks for the reply but your example does not do what I was asking

(1) The validation summary lists the offending fields. I do not want
the offending fields listed there.

(2) I want the offending field's font color to change. All you are
doing is adding a warning box.

Is there any way to do this without writing code? (Not that I mind,
but I would like to use Microsoft's built in stufff, but once again it
looks like it is useless) Or do I have to buy that guy who posted's
component?

thanks

-dan


Shan Plourde wrote:
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 :P :

.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 West wrote:


Nov 18 '05 #7

Shan,

OK, thanks for your help. I just wanted to exhaust all possibilities
within .net before I wrote my own or bought someone else's product.

Regards,

ed

Shan Plourde wrote:
Yes you're right, I am doing 2 things in my example:
1. Listing the offending fields
2. Displaying an image next to the label (a warning icon image) which
makes the label stand out on the page

So my approach is different from what you're trying to do. Out of the
box I don't think you can do this without writing code. You could
possibly extend the existing validation/UI model, perhaps such as:
<RequiredFieldValidator
ValidationLabel="<your label name>"
ValidationLabelStyle="<your style>"
/RequiredFieldValidator>

This way you would not have to then do any programmatic intervention. Of
course, you can always buy that other guys stuff if that's too much work :P

Shan Plourde

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nicolas | last post by:
How can I have only one RequiredFieldValidator to control two TextBox webcontrols so that only one message is displayed <asp:Label id="lbl_UserName" runat="server"></asp:Label><br> <asp:TextBox...
4
by: Joe | last post by:
Hello, I have created a login page using dotnet. I am using requiredFieldValidator and noticed that the code works fine in IE but not in Netscape, Opera, Mozilla, Firefox, etc. For example...
5
by: Fernando Lopes | last post by:
Hi. I want to show an image in a requiredfield validator instead of "*". So, I 'm set the requiredfieldvalidator attributes like following: <asp:RequiredFieldValidator id=rfvFirstName...
2
by: Mike P | last post by:
Is it possible to change the forecolor of a Span programmatically? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com ***
5
by: Bob Achgill | last post by:
Label example: "See the dog run." I would like to be able to highlight a given word in the example label using another color than the rest of the words in the sentence and/or maybe underline...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
4
by: Siah | last post by:
Hi, I wanted to dynamically update pieces of my page in the following fashion. Look at the following html code: <span id='person_23_name'> Mike </span> <span id='person_28_name'> Siah </span>...
1
by: Randy | last post by:
I've got an ASP VS 2005 project. I'm trying to figure out how to programmatically change the font of a label. From memory, this was done easily in 2003, but the Font property is read-only. Can...
6
by: andrew.ames | last post by:
Hi I have a pretty basic windows application created in Visual Studio 2005 and VB.NET. I set my Form's font to Arial 8.25pt, so when i added a label and a button they automatically have a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.