Catch OnFocus and OnBlur of an ASP.NET Label

J

Jim

Can anyone help me, I'm trying to catch the OnFocus and OnBlur events
for an asp.net label. I want to change the forecolor of the label when
it is moused over, and then revert it back when the focus is taken
away. Thanks in advance for any help.
 
S

Scott Mitchell [MVP]

Jim said:
Can anyone help me, I'm trying to catch the OnFocus and OnBlur events
for an asp.net label. I want to change the forecolor of the label when
it is moused over, and then revert it back when the focus is taken
away. Thanks in advance for any help.


Jim, I am assuming you are wanting to do this client-side? If so, just
set the onmouseover and onmouseout events via the Attributes collection:

// C#
myLabel.Attributes["onmouseover"] = "this.style.color = 'blue';";
myLabel.Attributes["onmouseout"] = "this.style.color = 'black';";


I talk more about fiddling with client-side script through server-side
code in my article:

Working with Client-Side Script
http://msdn.microsoft.com/asp.net/u...ibrary/en-us/dnaspp/html/ClientSideScript.asp

hth
 
C

Chris

Scott, I tried your link but it doesn't bring up your page. Do you have an
recommendation fro a dropdownlist that I need to re-bind when a user clicks
on it? The issue is that I provide a pop-up so the user can add a new option,
but when they close the parent page's list is not updated. I can not refresh
the screen since that will erase the other selected field values, user's tend
to get upset when you do that :). So if I re-bind the list to the contorl
then all the options are represented.

thanx.

Scott Mitchell said:
Jim said:
Can anyone help me, I'm trying to catch the OnFocus and OnBlur events
for an asp.net label. I want to change the forecolor of the label when
it is moused over, and then revert it back when the focus is taken
away. Thanks in advance for any help.


Jim, I am assuming you are wanting to do this client-side? If so, just
set the onmouseover and onmouseout events via the Attributes collection:

// C#
myLabel.Attributes["onmouseover"] = "this.style.color = 'blue';";
myLabel.Attributes["onmouseout"] = "this.style.color = 'black';";


I talk more about fiddling with client-side script through server-side
code in my article:

Working with Client-Side Script
http://msdn.microsoft.com/asp.net/u...ibrary/en-us/dnaspp/html/ClientSideScript.asp

hth


--

Scott Mitchell [ASP.NET MVP]
(e-mail address removed)
http://www.4GuysFromRolla.com/ScottMitchell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top