Click here to Skip to main content
15,939,620 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have a scenario that when focus comes on textbox the color of button should be changed. Can anyone help me with that in ASP.NET?
Updated 29-May-15 11:16am

1 solution

For future reference, a simple google search can help you out quickly.

Use the onfocus event of the textbox. And then have it call a javascript function which changes the color of the button. has a good interactive way to see how the onfocus event works. In this case they change the textbox color but changing the color of the button should be trivial at that point.[^]. Click the "Try it yourself" button.
Share this answer
Keyur Dodiya 29-May-15 16:20pm    
I have tried this. but its not working.

<form id="form1" runat="server">

<asp:TextBox ID="TextBox1" runat="server" onfocus="changeColor()">
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />

<script type="text/javascript">
function changeColor()
var btnclr = document.getElementById("Button1"); = "blue";
ZurdoDev 29-May-15 16:24pm    
bachgroundcolor is wrong. backgroundColor - case sensitive and spelled correctly.

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