OnClientClick isn't firing for ImageButton
本文关键字:firing for ImageButton isn OnClientClick | 更新日期: 2023-09-27 18:17:10
我有一个ASP。OnClientClick()应该触发一个js函数,从两个文本字段读取值,将其发送到服务器端的WebMethod。WebMethod将它发送给另一个处理存储的实体方法。我试过通过在服务器端设置WebMethod和存储方法中的断点来调试,但都没有达到。然后,我尝试使用Mozilla Firebug工具在客户端设置一个断点。js函数永远不会被调用,页面只是刷新。我在另一个js函数中设置了一个断点,它被完美地跟踪了。任何帮助吗?
ASP
<asp:ImageButton input="image" ID="btnSend" ImageUrl="Images/send_button.jpg"
runat="server"
onclientclick="javascript:handle(); return false">
</asp:ImageButton>
JS
function handle() {
window.$get("#" + "<%= btnSend.ClientID %>").click(
function () {
var txtVC = window.$get("#" + "<%= txtVC.ClientID %>").value();
var txtMsg = window.$get("#" + "<%= tbMgSend.ClientID %>").value();
if (txtVC != "" || txtMsg != "") {
window.PageMethods.SendMsg(txtVC, txtMsg, txtMessageResult);
return window.$get("#" + "<%= lblMessageStatus.ClientID%>").value("SUCCESS"),
alert("SUCCESS");
}
else {
return alert("Text Message is Empty!");
}
});
}
function txtMsgResult(result) {
if (result != '') {
window.$("#" + "<%= lblMessageStatus.ClientID %>").innerHTML = result;
alert("SUCCESS");
}
}
我试过以下方法:* OnclientClick与不返回* $get带和不带concat(+)*将服务器端更改为方法而不是web方法,这也不会触发
你试过没有return false
吗?
<asp:ImageButton input="image" ID="btnSend" ImageUrl="Images/send_button.jpg"
runat="server"
onclientclick="handle()">
</asp:ImageButton>
也许它不工作,因为它自动返回。我不确定是否有办法在ImageButton中关闭它。为什么不使用HTML控件呢?