Skip to content Skip to sidebar Skip to footer

Onload Client Event For Image Control

I need to bind client side onLoad event with ASP.Net Image control. I have tried it for quite some time with no success. Function Name onload='onLoadFunction(this)' Script: functio

Solution 1:

$("img #xyz").bind("load", function () { $(this).css("visibility", "visible"); });

Solution 2:

The OnLoad attribute is used to add an event handler the Load event, which is a server side event, not client side.

If you want create the onload attribute of the generated image element, you need to use Attributes collection

imgTopFourImg2.Attributes["onload"] = "onLoadFunction(this)";

EDIT from comments

Since the image is inside a repeater item this is not available in code behind. Handle ItemDataBound event:

voidR1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {

          // This event is raised for the header, the footer, separators, and items.// Execute the following logic for Items and Alternating Items.if (e.Item.ItemType == ListItemType.Item 
                  || e.Item.ItemType == ListItemType.AlternatingItem) 
             {

                var imgTopFourImg2 = e.Item.FindControl("imgTopFourImg2") asImage;
                if (imgTopFourImg2 != null)
                    imgTopFourImg2.Attributes["onload"] = "onLoadFunction(this)";
             }
          }
       }  

Solution 3:

$("#imgTopFourImg2").bind("load", function () { $(this).show(); });

It's worth looking into the show() and hide() methods, since you're already using jQuery.

Solution 4:

$("img #id").bind("load", function () { $(this).css("visibility", "visible"); });

Post a Comment for "Onload Client Event For Image Control"