Is there a javascript event that will always fire upon postback?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john

    Is there a javascript event that will always fire upon postback?

    I would like to do some client side stuff whenever my page is posting
    back. My page has a lot of different buttons and links that will cause
    a postback. I would rather not have to put something in each of their
    "onclick" functions. I would rather have a global OnPostback function
    or something like that. I tried using the form's onsubmit function,
    but it only gets called when my buttons are clicked; it doesn't get
    called when a link gets clicked or a dropdown list causes a postback.
    I noticed that these things call the ASP.NET javascript function
    __doPostBack. I don't know if I could somehow modify the __doPostBack
    function to call my function that does stuff before a postback. Any
    ideas?
    thanks in advance.
  • Peter O'Reilly

    #2
    Re: Is there a javascript event that will always fire upon postback?

    Try:

    document.MyForm .submit();

    within one of your client side DOM object's onClick event procedure.

    --
    Peter O'Reilly


    Comment

    • Scott

      #3
      Re: Is there a javascript event that will always fire upon postback?


      The easiest way I know (it's a hack) is to forward the _doPostBack to my own function and do what I
      need in that new function then call _doPostBack (make sure you always force a the _doPostBack
      generation on a page, the framework is clever enough to not include it sometimes).

      Something like:


      <script language="javas cript">
      <!--
      function MyDoPostBack(ev entTarget, eventArgument)
      { // do local stuff
      if (theform.onsubm it == null || theform.onsubmi t()) {
      return __oldPostBack(e ventTarget, eventArgument);
      }
      }
      var __oldPostBack = __doPostBack;
      __doPostBack = MyDoPostBack;
      // -->
      </script>
      Scott

      "john" <johngilmer@yah oo.com> wrote in message
      news:2947476e.0 404090640.58a72 2ce@posting.goo gle.com...[color=blue]
      > I would like to do some client side stuff whenever my page is posting
      > back. My page has a lot of different buttons and links that will cause
      > a postback. I would rather not have to put something in each of their
      > "onclick" functions. I would rather have a global OnPostback function
      > or something like that. I tried using the form's onsubmit function,
      > but it only gets called when my buttons are clicked; it doesn't get
      > called when a link gets clicked or a dropdown list causes a postback.
      > I noticed that these things call the ASP.NET javascript function
      > __doPostBack. I don't know if I could somehow modify the __doPostBack
      > function to call my function that does stuff before a postback. Any
      > ideas?
      > thanks in advance.[/color]


      Comment

      • john

        #4
        Re: Is there a javascript event that will always fire upon postback?

        Thanks for the response. I actually found a couple of javascript
        events that fire when i want them to: onstop and onbeforeunload. But
        they might only be available for IE.

        Comment

        Working...