my aspx (html) code is like below :
this is first button (something that should act like a normal button , i used anchor because of some nice css job) :
<p id="PaymentParag">
<a id="PaymentLink" onclick="SubmitForm();" name="PaymentLink" runat="server"
onserverclick="PaymentLink_Click" alt="Payment" title="Payment"></a>
</p>
as you see i have some server side code in onserverclick...
and this is another button :
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
and my jquery code :
function SubmitForm() {
$('#form1').submit();
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$(function () {
$('#form1').submit(function (e) {
alert('a');
var error = [false, false, false, false, false];
var text1 = '';
var text2 = '';
var radtxtEmail = $find("<%= radtxtEmail.ClientID %>");
text1 = radtxtEmail.get_value();
var radMaskedtxtMobile = $find("<%= radMaskedtxtMobile.ClientID %>");
text2 = radMaskedtxtMobile.get_value();
var ErrorsInsideMessageBox = $('#ErrorsInsideMessageBox');
ErrorsInsideMessageBox.html('');
var FormMessages = $('#FormMessages');
if (text1 == '' && text2 == '') {
error[0] = true;
}
if (error[0]) {
ErrorsInsideMessageBox.append(FormMessages.html());
e.preventDefault();
}
});
});
clicking on second button causes submit and related postback...
when error[0] = true we only have submit , not postback...
so , it seems every thing is normal about second button (regular asp.net button)
but my problem is about anchor (submit and postback)...
when i click it we have only postback , not submit , because of adding runat="server" and onserverclick="PaymentLink_Click"...
so i added onclick="SubmitForm();" for submitting form1...
but at this time i do n't know why we still have postback when error[0] = true -> e.preventDefault();
edit after comments :
i replaced that anchor by a link button like below :
<asp:LinkButton onClientclick="SubmitForm();" ID="PaymentLink" runat="server" onclick="PaymentLink_Click"></asp:LinkButton>
but i don't know why linkButton does not couse submit (like anchor) so i forced to add onClientclick="SubmitForm();
after doing this i still have postback when error[0]=true;
how can i prevent this postback ?
thanks in advance