开发者

Wait on loading SharePoint Webparts - timing issue

I'm experiencing what appears to be a timing issue when loading a few webparts in the same SharePoint 2007 site.

Currently I have a few webparts on my site, all aligned vertically aligne开发者_开发知识库d. I want the bottom-most webpart to load last, because it has a component that will be rendered to do a jQuery .offset().top (which gets the top left position of the component at the time the code is executed). Currently, the component appears at an incorrect place every time I reload the page. The only time it is at the correct place is when there are no other webparts above it.

For example:

WebPartWithComponent the first one on the page:

WebPartWithComponent <-- component rendered here correctly.
WebPart1
WebPart2
WebPart3

Other webparts in front of the WebPartWithComoonent on the page:

Webpart1
Webpart2 <-- component rendered here instead.
WebpartWithComponent <-- this is where the component should be rendered
Webpart4

Are there any ways to ensure the webpart with the component to load last, or start to load when the other webparts have completed loading, or wait at a particular point in the code until the other webparts have completed loading?

The webparts are rendered in jQuery (js) files.

Thanks.


Could you use jQuery ready function in your last web part?

http://api.jquery.com/ready/

$(document).ready(function() {
   //do your stuff
});

Or if you have that, setup some kind of tracking array in your web parts:

if(typeof(gWebParts)=="undefined") {
gWebParts = new Array()
}
gWebParts[gWebParts.length] = someobject

Then when they have loaded, set some variable

gWebParts[i].loaded = true

And in your final webpart, setup a timer

setInterval(function() {
   if(gWebParts all loaded) {
      clearInterval()
      //do your stuff
   }
}, 250)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜