Click here to Skip to main content
15,915,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to make textbox border red in colour when the user submits the form without specifying a value in the textbox, I want the textbox to have red borders.
Posted
Comments
Raje_ 8-Mar-13 7:12am    
Why are you down voting the answers? If you down vote any answer then please write a comment about your reason for down voting.

you can try this:
your html code:
ASP.NET
 <asp:textbox id="txtName" runat="server"></asp:textbox>
 <asp:button id="btnSave" runat="server" text="Save"
             OnClientClick="return validate();" />
</asp:button>


your javascript function:
JavaScript
function validate() {
    var txt = document.getElementById('<%= txtName.ClientID %>');
    if (txt.value == "") {
        txt.style.border = "1px solid Red";
        return false;
    }
 }



Good luck.
 
Share this answer
 
v2
When validation fails for a control - it'll add a css class to the control in the html. Look at your rendered html(Right click on browser --> View Source) and check out the class for TextBox. Then edit your css to include a new style for the failed validation.
Like this:
CSS
input.input-validation-error,
textarea.input-validation-error,
select.input-validation-error
{
    background: #FEF1EC;
    border: 1px solid #CD0A0A;
}



--Amit
 
Share this answer
 

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