0

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

SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • Why you don't use the LinkButton server control? It also renders into an anchor. – Yuriy Rozhovetskiy Jun 27 '11 at 13:24
  • @HalfTrackMindMan thanks for comment - i converted it to a link button - but still have this problem / every think is like my upper anchor... – SilverLight Jun 27 '11 at 13:40
  • Maybe I don't understand your aim but what sense of the SubmitForm method? If it performs validation before for has posted back to server then you can use following method: set onClientclick="return ValidateForm();" and if you have some errors on the page the return false from that method, elsewhere return true. – Yuriy Rozhovetskiy Jun 27 '11 at 17:13
  • @HalfTrackMindMan thanks for ur attention ... by your way i can do my job - but what about that problem ? plz see this related link -> http://stackoverflow.com/questions/6496533/jquery-submit-function-problem-with-anchor-in-asp-net-we-added-runat-server – SilverLight Jun 27 '11 at 18:10

1 Answers1

0

Update

Now understand what you say about.

Submit and post back is the same think.

This line totally confuse me. When you expect the onserverclick to run ? when there is a submit, that means a postback.

<a id="PaymentLink" onclick="SubmitForm();" name="PaymentLink" runat="server"
  onserverclick="PaymentLink_Click" alt="Payment" title="Payment">

I think that you need to change a little your flow logic of your page.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • thanks for answer / still have postback - besides i have another codes after that if and i think they won't execute by return false; – SilverLight Jun 27 '11 at 13:33
  • ok - let me explain my goal ... when i click that anchor without onclick="SubmitForm();" we have postback - so i thought we have submit , but not , because we wo n't see alert('a'); therefore i added onclick="SubmitForm();" because i need form submit for some reason / i have a validator div (showing validation summary) -> a Modal , and this is my reason to prevent postback and remember after page.isvalid i will need server-side anchor codes ! what can i do about this / i am confused too ... – SilverLight Jun 27 '11 at 13:55