I am working on a website in ASP.NET and I need to run a JavaScript function on page load from a content page and I also have a user control that needs to have some JavaScript executed on page load. I'm new to JavaScript and I'm not completely familiar with how our pages work (I'm also new on this project) but here's what I know.
The master page of our site implements some JavaScript on load and it allows the content pages to do on load events by allowing them to implement body_onload
function mp_onload()
{
if(window.body_onload != null)
window.body_onload();
}
On one of out content pages, I have several user controls that also need to execute on load functions. I've tried to do chain the events like this but am not having any luck.
In the user control:
function body_onload() {
addLoadEvent(cpWidget_onload);
}
function cpWidget_onload() {
makeExpandCollapse508('WidgetCollapsiblePanel');
}
function addLoadEvent(func) {
var oldonload = window.onload;
if(typeof window.onload != "function")
window.onload = func;
else
window.onload = function() {
oldonload();
func();
}
}
On the content page:
function body_onload() {
makeExpandCollapse508('SelectPlanTypesCollapsibleExtender');
}
I stepped through this code in FireBug, but it doesn't seem to ever enter the cpWidget_onload function. I'm guessing that the content page's body_onload is getting deleted by the user control's body_onload?
Thanks in advance! Any help is greatly appreciated.