I was experimenting with the DragPanelExtender recently, and almost immediately ran into the question of how to position it upon opening.
There are a lot of articles to be found on this question, and they always deal with it by means of a JavaScript function called pageLoad(), which is called by the ASP.Net Ajax framework sometime while the page is loading.
Now my application already has a pageLoad() function in the MasterPage, so adding a function of the same name in the ContentPage just did not work, as it would not be called by the framework.
My knowledge of JavaScript is not too profound, and I found that a function definition in JavaScript is actually a property of the window object. The hint was a line in the MicrosoftAjax.js file:
if (window.pageLoad) window.pageLoad(this,a);
meaning: if there is a defined function named pageLoad(), it is a property of the window object, and the value of the property is not null (== not false), and I can call it.
The solution was clear to me soon: if I need a pageLoad() method in the ContentPage, I need to name it differently and check for its definition in the MasterPage.
The pageLoad() in the MasterPage looks like this:
function pageLoad(sender, args)
{
...
// ... do my MasterPage JavaScript stuff...
...
if (window.contentPageLoad) {
window.contentPageLoad(sender, args);
}
}
and the ContentPage has its equivalent contentPageLoad() function:
function contentPageLoad(sender, args)
{
// do something
}
February 22, 2009 at 20:58 |
[...] Read the original here: JavaScript pageLoad() for MasterPage and ContentPage « devioblog [...]
April 13, 2009 at 19:03 |
Thanks for the post. Thanks to your post I resolved a problem with multiple update panels in both MasterPage and conten pages.
September 15, 2009 at 20:17 |
I also want to thank you for this posting. It was a great help and something that I would surely not have figured out on my own!
October 6, 2009 at 8:03 |
Thanks for this post. It really works and saves my time.
October 14, 2009 at 6:17 |
[...] Credit goes to devioblog. [...]