Follow this simple steps
1. write Following javascript code on head tag
function changeColor(source, args)
{
var txtuser = document.getElementById('<%= txtUserName.ClientID %>');
if(args.Value.length == 0)
{
txtuser.style.border="red solid 1px";
args.IsValid = false;
}
else
{
txtuser.style.background = 'white';
args.IsValid = true;
}
}
2. Drag Textbox on Form give id="txtUserName"
<asp:TextBox ID="txtUserName" runat="server" ></asp:TextBox>
3. Drag CustomValidator control from toolbox.Set Following Properties
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtUserName"
ErrorMessage="" ValidateEmptyText="True"
ClientValidationFunction="changeColor"></asp:CustomValidator>
4.Take one Button on form.
5. Run Website.
Change TextBox Color on Validation Fail in Asp.net
This Blog Show how to change TextBox color when validation fails.


Sandeep KumarPosted May 2, 2015, 5:49 PM EDT
hi
Harshal ThakrePosted Aug 8, 2014, 11:50 PM EDT
what we can do for multiple textboxes
NeelimaPosted Oct 29, 2012, 6:48 PM EDT
while am coding the above program am getting error at the document...why is it so???
Suthish NairTOP 100Posted May 17, 2011, 3:04 AM EDT
call Suthish :)
Ankit NandekarPosted May 17, 2011, 2:21 AM EDT
thnx suthish sir i m updating.
Suthish NairTOP 100Posted May 17, 2011, 2:17 AM EDT
update the blog title....