问题
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