0

We have a base page in our application that all other pages derive from. We have been inserting a record in the database for each page request to track application usage stats. Now we'd like to also log some of the data from after the page has been rendered, so we injected some javascript into the page via:

ScriptManager.RegisterStartupScript(this, this.GetType(), "readyTime", sReady, true);

This injects a script with some jQuery that says 'when the window.load event fires, send some data to a webservice so we know how long the page took to download to the client and render.

It works on an initial page request, but it doesn't work on async postbacks. I added code to the effect of:

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
 function EndRequestHandler(sender, args)
 {
   // webservice call here
 }";

The problem is, the async code does fire at the end of the async postback, but the key it uses for the log entry is the same as the one on the intial request. The javascript in the page is given a key when the page is generated, and that javascript is not being updated. I set a breakpoint, and the ScriptManager call is being executed, but the script on the page stays the same after each postback.

Anyone know if this possible?

EDIT: I saw this post: Client side script won't execute with ScriptManager But because I'm in a base page I'm not sure if I can find out exactly which control caused the postback. (At least the code I tried using __EVENTTARGET didn't work, because sometimes it's buried in user controls or grids)

Community
  • 1
  • 1
LoveMeSomeCode
  • 3,888
  • 8
  • 34
  • 48

1 Answers1

0

If using ScriptManager then You can use following snippet

if(ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
{
   ...
}
AlfeG
  • 1,475
  • 4
  • 18
  • 33
  • But I know it's an async postback. I just need to update the javascript with the new key on the async postback. The key in the javascript never changes. – LoveMeSomeCode Aug 08 '11 at 14:09