Hi guys,
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?
Hi guys,
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 + ");");
On solution would be to use a css class and jQuery:
<img id="generatedId" class="myHoverImage" />
javascript:
$("img.myHoverImage").mouseover ( function() {
// you can access the generated id:
alert ( this.id );
// --> your code goes here <-- \\
});
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 + ");");