RequiredFieldValidator BUT highlight the textbox

Camillia
Camillia used Ask the Experts™
on
I have a page with lots of fields (it's a job application page). Right now, i have , for example, the code below. I put a red * next to the textbox that should be filled out and I popup a msg.

What I want to do is to highlight the textbox..instead  of having a red star next to the textbox. When user enters in the textbox (fills out required fields), I want the color to go away. Just like the *. When user fills in the required field, the star goes away..

anyway of doing this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
Top Expert 2010
Commented:
Yes, you can do this by validation callout extender....

http://www.asp.net/ajax/ajaxcontroltoolkit/samples/ValidatorCallout/ValidatorCallout.aspx 

you can avoid the callout and just use the style for the textbox
do i still need to have the required field validator there?
"To use this control, add an input field and a validator control as you normally would. "

Is that correct>
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Top Expert 2010

Commented:
you should still have required field validator...

validation callout extender is just an extender to your validator which is already present

anyway to turn off that popup and just have the textbox background color? i cant find examples of turning off the popup..
Top Expert 2010

Commented:
If you go thro the site, you will see a ValidatorCallout Theming  section you can apply all the css there so thatthe popup is not shown
Top Expert 2013
Commented:
I think that's not possible without modifying the actual validatorCallout Extender code in the ToolKit
Or may be extending the existing validators.
May be you can think of jQuery validate plugin instead.
One more option you can do javascript validation. Which will meet your needs.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<script type="text/javascript" language="javascript" >
            
function ValidateFields()
{
    var retvalue = true;
    
    if (document.getElementById('<%= TextBox1.ClientID %>').value == '')
    {
        document.getElementById('<%= TextBox1.ClientID %>').style.backgroundColor = 'red';
        retvalue = false;
    }
    if (document.getElementById('<%= TextBox2.ClientID %>').value == '')
    {
        document.getElementById('<%= TextBox2.ClientID %>').style.backgroundColor = 'red';
        retvalue = false;
    }
    if (document.getElementById('<%= TextBox3.ClientID %>').value == '')
    {
        document.getElementById('<%= TextBox3.ClientID %>').style.backgroundColor = 'red';
        retvalue = false;
    }
    
    return retvalue;
}
            
</script>
    <form id="form1" runat="server">
    <div>    
        <table >
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" onkeyup="if (this.value != '') { this.style.backgroundColor = 'white' }"></asp:TextBox>                    
                </td>
            </tr>
            <tr>
                <td>                
                    <asp:TextBox ID="TextBox2" runat="server" onkeyup="if (this.value != '') { this.style.backgroundColor = 'white' }"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" onkeyup="if (this.value != '') { this.style.backgroundColor = 'white' }"></asp:TextBox>
                </td>                
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return ValidateFields();" onclick="Button1_Click" />
                </td>               
            </tr>           
        </table>    
    </div>
    </form>
</body>
</html>

Open in new window

with the javascript one, i need to remove the red when user types in the textboxes. I think Javascript has to return true somehow...how can i make that change?
In TextBox onkeyup event, I have given code to remove red color.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial