button causing postback even with return false in javascript

Last post 07-11-2009 5:47 AM by starsastry. 5 replies.

Sort Posts:

  • button causing postback even with return false in javascript

    02-23-2007, 2:20 PM
    • Participant
      1,717 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 856

    With my submit button, I want to avoid a postback if the user erred with my javascipt below and my button is the following but the page posts back everytime. Can this be helped?

    <

    asp:Button ID="Button2" runat="server" OnClientClick = "ValidateBOX()" Style="z-index: 106; left: 394px; position: absolute; top: 29px" Text="validate boxes" />

     

    function ValidateBOX()
        {
            var a= document.getElementById('textbox2');
            var b= document.getElementById('textbox3');
           
            if (a.value.length == 0 | b.value.length == 0)
            {
                alert('Please enter value in both of the text boxes 2 & 3');
                return false;
             }
             else
            {
            return true;
            }
    }

  • Re: button causing postback even with return false in javascript

    02-23-2007, 2:25 PM
    Answer
    • Participant
      1,526 point Participant
    • James_2JS
    • Member since 02-13-2006, 3:21 PM
    • Posts 335

    try OnClientClick="return ValidateBOX();"

    That way it will return the value of the function up!!

  • Re: button causing postback even with return false in javascript

    02-23-2007, 2:32 PM
    • Participant
      1,717 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 856

    So that's the way it's done...........

    Smile

     

  • Re: button causing postback even with return false in javascript

    02-23-2007, 2:33 PM
    • Participant
      1,717 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 856

    So that's the way it's done...........Smile

     

  • Re: button causing postback even with return false in javascript

    06-26-2009, 8:16 AM
    • Member
      70 point Member
    • nandu_2322310
    • Member since 02-25-2009, 6:50 AM
    • New Delhi, India
    • Posts 77

    hello friend

    i have same problem

    in this case

    OnClientClick="getval();" OnClick="Button_Click"/>

    my asp.net validation work properly, but script part no working properly,


    OnClientClick="return getval();" OnClick="Button_Click"/>


    my asp.net validation not working properly, but script part working properly,


    What happening, plz explain

    N_Rawat

    Plz Mark AS Answer if Any Help
  • Re: button causing postback even with return false in javascript

    07-11-2009, 5:47 AM
    • Member
      2 point Member
    • starsastry
    • Member since 06-24-2009, 9:56 AM
    • Posts 1

    Me too facing the same issue ...any 1 please help us ..Need solution immediately ... 

Page 1 of 1 (6 items)