autopostback - javascript intercept and cancel

Discussion in 'ASP .Net' started by Susan van Houen, Jul 17, 2003.

  1. Hi All,

    How do I intercept an autopostback on the client side
    and prevent it from executing the submit?

    In classic ASP I used to intercept the on_submit and
    just

    return false;

    but it doesn't seem to work anymore.

    Any ideas?

    Sincerely,
    S
     
    Susan van Houen, Jul 17, 2003
    #1
    1. Advertising

  2. Hi Susan,

    Please add the javascript function to your server control
    as given below.
    Button1.Attributes.Add("onclick", "return FunctionName
    ();");

    Now put the function in html section. If success then you
    can return true else false.

    So it wont submit the page if client side function fails.

    Let me know if you ned furtehr help.
    Regards
    Sreejumon


    >-----Original Message-----
    >Hi All,
    >
    >How do I intercept an autopostback on the client side
    >and prevent it from executing the submit?
    >
    >In classic ASP I used to intercept the on_submit and
    >just
    >
    > return false;
    >
    >but it doesn't seem to work anymore.
    >
    >Any ideas?
    >
    >Sincerely,
    >S
    >
    >
    >.
    >
     
    Sreejumon[MVP], Jul 17, 2003
    #2
    1. Advertising

  3. Susan van Houen

    Marina Guest

    The reason that doesn't work, is because by setting AutoPostBack to true,
    that generates an onselectedindexchanged handler, which just submits the
    form. So the one you created, just get ignored.

    I would instead suggested that you turn autopostback to false, and just keep
    your handler. This handler should then sometimes manually submit the form by
    calling its submit method.

    "Susan van Houen" <> wrote in message
    news:...
    > Thank you for your response, but I can't get it to work.
    >
    > My control looks like this
    > <asp:dropdownlist id="ddlPoi" style="Z-INDEX: 125; LEFT: 32px; POSITION:
    > absolute; TOP: 445px" runat="server"
    > OnSelectedIndexChanged="lbLocoptions_SelectedIndexChanged"
    > AutoPostBack="True">
    >
    > When OnSelectedIndexChanged is fired I want it to pass through a client

    side
    > javascript where I can evaluate if I actually want the autopostback to
    > complete or not.
    >
    > In the Page_Load of the behind code I have
    >
    > lbLocoptions.Attributes.Add("onselectedindexchanged", "return
    > lbLocoptions_onchange();")
    >
    > and in the client I have
    >
    > function lbLocoptions_onchange(){
    > return false;
    > }
    >
    > Still, the AutoPostBack completes every time.
    >
    > Sincerely,
    > S
    >
    > "Sreejumon[MVP]" <> wrote in message
    > news:016301c34c9b$1faf4d50$...
    > > Hi Susan,
    > >
    > > Please add the javascript function to your server control
    > > as given below.
    > > Button1.Attributes.Add("onclick", "return FunctionName
    > > ();");
    > >
    > > Now put the function in html section. If success then you
    > > can return true else false.
    > >
    > > So it wont submit the page if client side function fails.
    > >
    > > Let me know if you ned furtehr help.
    > > Regards
    > > Sreejumon
    > >
    > >
    > > >-----Original Message-----
    > > >Hi All,
    > > >
    > > >How do I intercept an autopostback on the client side
    > > >and prevent it from executing the submit?
    > > >
    > > >In classic ASP I used to intercept the on_submit and
    > > >just
    > > >
    > > > return false;
    > > >
    > > >but it doesn't seem to work anymore.
    > > >
    > > >Any ideas?
    > > >
    > > >Sincerely,
    > > >S
    > > >
    > > >
    > > >.
    > > >

    >
    >
     
    Marina, Jul 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Folland
    Replies:
    2
    Views:
    1,694
    Jonathan Folland
    Mar 17, 2005
  2. super todd
    Replies:
    1
    Views:
    653
    Bruce Barker
    May 23, 2005
  3. Sandip Chitale
    Replies:
    0
    Views:
    393
    Sandip Chitale
    Jul 23, 2004
  4. Matteo
    Replies:
    1
    Views:
    5,027
    Allan Bruce
    Mar 31, 2005
  5. inetquestion
    Replies:
    3
    Views:
    462
Loading...

Share This Page