11

How do I load a javascript command (like an onload or onclick or something) after the update panel was just refreshed.

billsecond
  • 612
  • 3
  • 21
  • 50

3 Answers3

15

Embed these lines on your javascript tag

function foo()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args)
{
    // Do your stuff
    alert('Update Panel routine is now complete');
}

Then, put this on you body tag

<body onload="foo()">
  • 2
    Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead. – Kev May 10 '12 at 01:22
7
ScriptManager.RegisterClientScriptBlock(upPanel, upPanel.GetType(), "alert('hello world')", true);

You must call this on partial postback.

deostroll
  • 11,661
  • 21
  • 90
  • 161
  • just to clarify, this solutions can eventually result in script block overflow and ultimately crashing your browser, since it gets a new script block on each request. – netchkin Sep 30 '14 at 08:32
0

You could use ScriptManager. I'd think ScriptManager.RegisterClientScriptBlock should be useful. You can then execute JS after the page load. Other options include JQuery.live.

Candide
  • 30,469
  • 8
  • 53
  • 60