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.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

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