admin管理员组文章数量:1336586
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:
function onLoadFunction(img) {
$(img).css("visibility", "visible"); // Using jQuery
// img.style.visibility = "visible"; // Using just javascript.
}
Markup:
<asp:Image ID="imgTopFourImg2" runat="server" width="170px" height="112px" CssClass="ArticleImgHP" border="0" ImageUrl="hello.jpg" OnLoad="onLoadFunction(this)" />
It is not working for me i would appreciate if someone can help me with this.
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:
function onLoadFunction(img) {
$(img).css("visibility", "visible"); // Using jQuery
// img.style.visibility = "visible"; // Using just javascript.
}
Markup:
<asp:Image ID="imgTopFourImg2" runat="server" width="170px" height="112px" CssClass="ArticleImgHP" border="0" ImageUrl="hello.jpg" OnLoad="onLoadFunction(this)" />
It is not working for me i would appreciate if someone can help me with this.
Share Improve this question edited Apr 19, 2012 at 14:06 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Apr 19, 2012 at 13:55 LearningLearning 20.1k44 gold badges191 silver badges395 bronze badges 2- This is actually related to my previous question stackoverflow./questions/10227254/… – Learning Commented Apr 22, 2012 at 4:12
- If you check the link in my last ment you will get the plete picture.. – Learning Commented Apr 22, 2012 at 4:13
4 Answers
Reset to default 3$("img #xyz").bind("load", function () { $(this).css("visibility", "visible"); });
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 ments
Since the image is inside a repeater item this is not available in code behind. Handle ItemDataBound event:
void R1_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") as Image;
if (imgTopFourImg2 != null)
imgTopFourImg2.Attributes["onload"] = "onLoadFunction(this)";
}
}
}
$("#imgTopFourImg2").bind("load", function () { $(this).show(); });
It's worth looking into the show()
and hide()
methods, since you're already using jQuery.
$("img #id").bind("load", function () { $(this).css("visibility", "visible"); });
本文标签: cOnLoad client event for Image controlStack Overflow
版权声明:本文标题:c# - OnLoad client event for Image control - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742410782a2469743.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论