Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I change border and background color of the control when any of the validation fails after submit button clicked.
I searched this in google but most of the solution provided in jQuery, but I don't want to use jQuery.
Posted

1 solution

On button Click, try some thing like this

{

if (TextBox1.Text==Null|| TextBox1.Text="")
{
TextBox1.BackColor = System.Drawing.Color.Red;
}
 
Share this answer
 
Comments
Dinesh Ambaliya 1-Aug-12 9:04am    
but this code is called when all the validations are valid.
Santhosh Kumar Jayaraman 1-Aug-12 9:06am    
What do you want to do?When if any of the control has error, then you want to display right? The above code will do that if textbox1 dont have any values. You can alter the if conditions according to your logic
Dinesh Ambaliya 1-Aug-12 9:40am    
but I have putted required field validation control associated with textbox, so when I click the button without any text in the textbox, if condition in not called.
Santhosh Kumar Jayaraman 1-Aug-12 9:42am    
No wat i meant to say is just an example. You have to start it from there. For eg.you dont want textbox1.Text to have integer =6 , then


if (TextBox1.Text.ToString().Contains("6"))
{
TextBox1.BackColor = System.Drawing.Color.Red;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900