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:
Hi,

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?
Posted
Updated 29-May-15 11:16am
v2

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.

W3schools.com 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.

http://www.w3schools.com/jsref/event_onfocus.asp[^]. Click the "Try it yourself" button.
 
Share this answer
 
Comments
Keyur Dodiya 29-May-15 16:20pm    
I have tried this. but its not working.

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

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

</div>
</form>
<script type="text/javascript">
function changeColor()
{
var btnclr = document.getElementById("Button1");
btnclr.style.bachgroundcolor = "blue";
}
</script>
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