【问题标题】:OnClientClick isn't firing for ImageButtonOnClientClick 没有为 ImageButton 触发
【发布时间】:2011-12-07 19:35:10
【问题描述】:

我有一个 ASP.NET ImageButton,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 方法,并且也没有触发

【问题讨论】:

    标签: c# javascript .net imagebutton onclientclick


    【解决方案1】:

    你试过没有return false吗?

    <asp:ImageButton input="image" ID="btnSend" ImageUrl="Images/send_button.jpg" 
       runat="server"                                                            
      onclientclick="handle()">
    </asp:ImageButton>
    

    【讨论】:

      【解决方案2】:

      也许它不起作用,因为它是 autoPostBack。 我不确定是否有办法在 ImageButton 中将其关闭。为什么不使用 HTML 控件呢?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-09
        • 2016-09-14
        • 1970-01-01
        相关资源
        最近更新 更多