Sanal.org
till 01th May 2006
Categories
.NET (40)
Art (1)
Blogs (1)
Computers (6)
Information (13)
Internet (11)
Movies (5)
Music (19)
MY SQL (5)
People (16)
Russian (20)
Security (15)
SEO (3)
SQL SERVER (8)
Technology (6)
Turkey (2)
Video (7)
More
TOP 50
Turkish News


Archive
April (2008)
March (2008)
February (2008)
January (2008)
December (2007)
Novamber (2007)
October (2007)
September (2007)
August (2007)
July (2007)
June (2007)
May (2007)
April (2007)
March (2007)
February (2007)
January (2007)
December (2006)
Novamber (2006)
October (2006)
September (2006)
August (2006)
July (2006)
June (2006)
May (2006)
April (2006)
March (2006)
February (2006)
January (2006)
December (2005)
October (2005)
April (2005)
December (1969)

90

ROR

Sys.Application.add_load != window.onload


I remember seeing a sample which used Sys.Application.add_load to attach a function you’d normally want to run upon window.onload. It went like this:

function initFoo () {
  // Initialization code here...
}

Sys.Application.add_load (initFoo);

Having browsed the MS AJAX Library source code, I figured the Sys.Application provided a convenient event hook indeed since the class tapped window.load and window.unload for you:

Sys.UI.DomEvent.addHandler (
   window, "unload", this._unloadHandlerDelegate);

Sys.UI.DomEvent.addHandler (
   window, "load", this._loadHandlerDelegate);

To my surprize, initFoo was getting called on every AJAX callback. I figured there was no way get window to fire its onload event several times, so the Sys.Application class must’ve been involved a lot more than I thought.

The remedy is to either hook into window.onload directly:

Sys.UI.DomEvent.addHandler(window, "load", initFoo);

or avoid multiple initializations:

function initFoo () {
  var prm = Sys.WebForms.PageRequestManager.getInstance();

 if (prm.get_isInAsyncPostBack())
     return;

 // Initialization code here...
}

To me, the former looks cleaner and less kludgy than the latter.




0.015625
Bilgi Portalı | Forum | Haberler | Havacılık | Daily News | Noticias