admin管理员组文章数量:1355532
I had a input button to which I called a javascript function when clicked. But I want to add images to the button So I used a Image button but I am not able to call the Javascript function from the image button. How to run the javascript fn when the image button is clicked
<input id="send" type="button" value=" Preview on iPhone " onclick="javascript:preview()">
<asp:ImageButton OnClick="preview()" ID="send" runat="server" ImageUrl="Styles/Images/preview_iphone.png"
OnMouseOut="this.src='Styles/Images/preview_iphone.png'"
OnMouseOver="this.src='Styles/Images/preview_iphone_over.png'" />
I had a input button to which I called a javascript function when clicked. But I want to add images to the button So I used a Image button but I am not able to call the Javascript function from the image button. How to run the javascript fn when the image button is clicked
<input id="send" type="button" value=" Preview on iPhone " onclick="javascript:preview()">
<asp:ImageButton OnClick="preview()" ID="send" runat="server" ImageUrl="Styles/Images/preview_iphone.png"
OnMouseOut="this.src='Styles/Images/preview_iphone.png'"
OnMouseOver="this.src='Styles/Images/preview_iphone_over.png'" />
Share
Improve this question
asked Jan 31, 2012 at 14:47
Murthy Murthy
1,55211 gold badges31 silver badges45 bronze badges
3 Answers
Reset to default 6try the OnClientClick="javascript:preview()"
that's the one for the client side click.
from here
you can bind click event via jQuery, like this
$("#id_of_your_imagebutton").click(function(){
//your code for event here
});
If you use asp 4, you can set ClientIDMode="Static" to your ImageButton and get "send" for ID, or you can get ID via FireBug if you use earler versions
you can try like this, in code behind file.
Protected void Page_Load(object sender, EventArgs e)
{
send.Attributes.Add("onclick", "javascript:preview(); return false;" ) // retruning false will avoid postback
}
本文标签: cHow to run the javascript fn using OnClick button event (aspnet)Stack Overflow
版权声明:本文标题:c# - How to run the javascript fn using OnClick button event (asp.net) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743944823a2566210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论