OnClientClick 不会为 ImageButton 触发

发布于 2024-12-20 02:25:48 字数 1543 浏览 5 评论 0原文

我有一个 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 带或不带返回 * 带和不带 concat(+) 的 $get * 将服务器端更改为方法而不是 Web 方法,但这也没有触发

I have an ASP.NET ImageButton that OnClientClick() is supposed to fire a js function that reads the values from a two text fields, send it to a server-side WebMethod. With the WebMethod sending it to another entity method which handles the storage. I've tried debugging by setting breakpoints in the WebMethod and storage method on the serverside but neither is getting reached. I then tried setting a breakpoint on client-side using the Mozilla Firebug tool. The js function never gets called and the page just refreshes. I set a breakpoint in another js function and it was traced perfectly. Any help?

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");
        }
    }

I've tried the following:
* OnclientClick with and without return
* $get with and without concat(+)
* changing the server-side to a method instead of web method and that also didn't fire

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蛮可爱 2024-12-27 02:25:48

您是否尝试过不返回 false 的情况?

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

Have you tried it without the return false?

<asp:ImageButton input="image" ID="btnSend" ImageUrl="Images/send_button.jpg" 
   runat="server"                                                            
  onclientclick="handle()">
</asp:ImageButton>
爱已欠费 2024-12-27 02:25:48

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

Maybe it doesn't work because it autoPostBack.
I'm not sure there is a way to turn it off in an ImageButton. Why not use a HTML control instead ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文