How to change the background color in the Textbox on focus ?

Dec 21, 2009 Posted by Lara Kannan

I searched the solution for the following situation. In asp.net web application, gridview contains textbox in each row. When there is focus on the textbox, the background colour of the textbox must be yellow with bold otherwise it must be black with white text.

See the sample code: we reach the solution by simply adding onfocus and onblur event to the text box.


...
...

<asp:TextBox ID="text1" runat="server"
onFocus="this.style.background ='yellow'"
onBlur="this.style.background='white'"/>

....
....

Happy coding!

Share
Labels: ,

Post a Comment