在asp.net中单击图像按钮调用javascript函数
我试图在客户端按下图像按钮时调用 jquery 函数,下面是代码:
<asp:ImageButton ID="startUploadLink" runat="server"
onclick="startUploadLink_Click" />
$("#startUploadLink").click(function () {
$('#<%=FileUpload1.ClientID%>').uploadifyUpload();
return false;
});
想要在用户单击图像按钮时调用上述函数,还希望 onclick 图像按钮逻辑背后的一些代码应该与jquery的功能,有什么方法可以实现吗? 任何帮助或建议将不胜感激。
I am trying to invoke a jquery function when a client press the image button, below is the code:
<asp:ImageButton ID="startUploadLink" runat="server"
onclick="startUploadLink_Click" />
$("#startUploadLink").click(function () {
$('#<%=FileUpload1.ClientID%>').uploadifyUpload();
return false;
});
want to invoke the above function when a user click on image button , also want some code behind logic of onclick image button should work in conjuction with the jquery function, is there any way of achieving it.
Any help or suggestions will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接使用jQuery来绑定点击事件呢?您已经在这样做了,但可能不起作用,因为您没有寻找客户端 ID。我不知道为什么你做了正确的事情来查找
FileUpload1
但没有绑定点击事件,但这应该是你需要做的全部:jQuery 绑定将覆盖
onclientclick
> 但没有太多理由说明你应该同时使用两者。如果您已经在使用 jQuery 来绑定事件,那么最好只使用它。它们也可以很好地处理代码隐藏/回发。如果您想阻止表单从 jQuery 绑定事件发布,请在 javascript 中使用e.preventDefault()
,否则,使用默认操作(例如,从调用的 ASP.NET 回发函数) >href
) 将会发生。Why not just use jQuery to bind the click event? You are already sort of doing that, but probably it doesn't work because you aren't looking for the client ID. I'm not sure why you did the right thing for finding
FileUpload1
but not for binding the click event, but this should be all you need to do:jQuery bindings will override
onclientclick
but there's not much reason why you should use both. It's better to just use jQuery for binding events if you're already using it. They will work fine with codebehind/postbacks as well. If you want to PREVENT the form from posting from a jQuery bound event, then usee.preventDefault()
in the javascript, otherwise, the default action (e.g. the ASP.NET postback function called fromhref
) will occur.尝试在图像按钮上使用 onclientclick
Try using onclientclick on the imagebutton