jquery submit function problem with anchor in asp.net -> we added runat=“server” to anchor

故事扮演 提交于 2020-01-07 04:45:07

问题


my anchor code is like below :

<a id="PaymentLink" name="PaymentLinks" runat="server"
        onserverclick="PaymentLink_Click" title="Payment"></a>

form element like below :

<form id="form1" runat="server" onsubmit="alert('alibaba');return false;">

and submit function of jquery is like below :

            $(function () {
                $('#form1').submit(function (e) {
                    alert('alert2');
      });
});

why after click that anchor we only see alibaba alert ...
link button has this manner too...
but when we use regular asp.net buttons , we will see both alerts ...
how can we trigger submit function of jquery when that anchor is clicked ?

i need to use server side anchor for some reasons ...

thanks in advance


回答1:


How to capture submit event using jQuery in an ASP.NET application?




回答2:


Because the anchor (HyperLinkButton) is set to run on server and it fires onServerClick, the page is posted back to server and your client-side $('#form1').submit() function is not fired. You have to decide, how do you want to handle onClick event: server-side or client-side. You could also consider having the linkbutton call a WebMethod asynchronously and then handle callback on client.




回答3:


I took the solution mentioned by Yuriy and put it in a jQuery plugin: http://plugins.jquery.com/beforePostBack/.



来源:https://stackoverflow.com/questions/6496533/jquery-submit-function-problem-with-anchor-in-asp-net-we-added-runat-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!