Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register OnMouseOver-Event from CodeBehind?

I wan't to register the OnMouseOver and OnMouseOut-Event for an Image from the Code behind, because I must different if the user is logged in or not. Any ideas?

like image 506
PassionateDeveloper Avatar asked Jun 16 '26 09:06

PassionateDeveloper


2 Answers

You can add an attribute to the object.

e.g.

 Image img = new Image();
 img.Attributes.Add("onmouseover", "myjavascriptfunction();");

To set the paramater based on the id of the object, using this:

 Image img = new Image();
 img.Attributes.Add("onmouseover", "myjavascriptfunction(" + img.ClientID + ");");
like image 134
cjk Avatar answered Jun 18 '26 22:06

cjk


Using ck's example, you can achieve what you're trying to do using the ClientID property on your server control. Like this:

yourImage.Attributes.Add("onmouseover", "jsfunction(" + yourImage.ClientID + ");");
like image 32
Eric Lennartsson Avatar answered Jun 19 '26 00:06

Eric Lennartsson