views:

985

answers:

4

In my MasterPage, I have a ScriptManager that has a ScriptReference to my jquery.js file. This has always worked with no problems, all content pages that utilize jquery work fine.

Recently, I added the following javascript script block at the end of my MasterPage:

function pageLoad(sender, args) {
}

By simply adding the above pageLoad method, no jquery code is executed from any of my content pages. Why would just having a pageLoad in the Master Page have this effect?

Thanks in advance for any insight.

A: 

Why can't you just use:

$(document).ready(function() {
   // do that funky thing
}
Kezzer
In this particular case, I need the code I will be calling to run after every partial postback which only pageLoad() provides. I forgot about Sys.Application.add_init() though, I'm going see if using that helps.
+2  A: 

You might find the following discussion on pageLoad helpful.

http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/

Chris Lively
Thanks, I'm aware of it, great article.
+1  A: 

It looks like using Sys.Application.add_init() instead of document.ready() or pageLoad() in my Master Page resolved my issue.

Details about my issue are probably too lengthy but it may help someone else if I try to at least nutshell what's going on.

My Master Page has a "navigation" contenttemplate that houses the ASP.NET TreeView control. I wanted to keep the scrolled position (it has quite a few nodes in it) of that TreeView after postbacks. In order to do this, I attach a call to the following js function on the onscroll event of a div surrounding my TreeView control:

function SetDivScrollPosition() {
var strCook = document.cookie;
if (strCook.length > 0) {
    var cookies = strCook.split(";");
    for (var i = 0; i < cookies.length; i++) {
        var mySplit = cookies[i].split("=");
            document.getElementById(mySplit[0].replace(" ", "")).scrollTop = mySplit[1];
    }
}

}

However, I also have other scrollable divs in other content pages and I wanted to also keep track of those scrollable positions after postbacks (full or partial). So, what I had to do was to also call SetDivScrollPosition() from those content pages' document.ready() function.

A: 

Is it possible that the rendered version of your page (or included .js files) already has a pageLoad method defined? If that is the case, then your page might have pageLoad defined twice, which would cause the problem you describe.

David