开发者

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

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


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜