Tags: addhandler, ajax, aspnet, asyncpostback, handler, javascript, loaded, net, page, panel, runs, time, working

Javascript not working after AsyncPostBack


2,356 words with 4 Comments; publish: Sun, 06 Jan 2008 05:41:00 GMT; (10046.88, « »)

I have some javascript that runs perfect the first time the page is loaded. It's using $addHandler to add a handler to a panel. I have an UpdatePanel that is refreshing on the AsyncPostBack. After the first AsyncPostBack, all my javascript stops running. Any idea why?

All Comments

Leave a comment...

    • Is the panel inside the update panel that's refreshing? Is your call to $addHandler inside pageLoad?

      #1; Sun, 06 Jan 2008 05:42:00 GMT
    • Can you post some code..

      So it will help to resolve the issue...

      #2; Sun, 06 Jan 2008 05:43:00 GMT
    • I have this in thePage_PreRender event:

      'Run script each postback, even partial page postbacks

      ScriptManager1.RegisterClientScriptInclude(Me.Page, Me.GetType, "frmPics.aspx.js", "frmPics.aspx.js")

      My js file has a bunch of functions in it and this outside of a function...

      // add Handlers for drop event

      $addHandler($get('Panel1'),"drop", AlertWhenDropped1);

      I'm trying to run this external javascript file on every postback, even asyncpostback. It runs fine on a full page postback, but won't run on a asyncpostback. Any idea why not?

      #3; Sun, 06 Jan 2008 05:44:00 GMT
    • Thank the Lord I think I got it. I had to do this:

      'Run script each postback, even partial page postbacks


      'Must run this or the handler's won't get added on asyncpostback

      Dim scriptStringAs String ="<script> "

      scriptString +=" $addHandler($get('Panel1'), 'drop', AlertWhenDropped1); "

      scriptString += "</script>"

      ScriptManager1.RegisterStartupScript(UpdatePanel1, GetType(UpdatePanel), "justTesting", scriptString,False)

      For some reason it wasn't adding the handler on asyncPostBack. Doing it this way works for me. Thanks!
      #4; Sun, 06 Jan 2008 05:45:00 GMT