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?
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 + ");");
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 + ");");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With