Clay Angelly
Clay Angelly

Reputation:

ASP.NET Master Page + pageLoad() = kills jquery?

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.

Upvotes: 1

Views: 2507

Answers (4)

David
David

Reputation: 1774

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.

Upvotes: 1

Clay Angelly
Clay Angelly

Reputation:

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.

Upvotes: 1

ChrisLively
ChrisLively

Reputation: 88044

You might find the following discussion on pageLoad helpful.

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

Upvotes: 2

Kieran Senior
Kieran Senior

Reputation: 18220

Why can't you just use:

$(document).ready(function() {
   // do that funky thing
}

Upvotes: 0

Related Questions