views:

129

answers:

2

I have a master page that references jquery + jqueryui. Everything is fine. In the content page I placed:

  $(document).ready(function () {
        $("#tabs").tabs();
    });

It turns out that the ready event fires BEFORE the html of the content page is loaded :/. So, how to determine when the whole content page is loaded ?

Edit this is my markup:

master page:

<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Scripts>
    <asp:ScriptReference Path="~/Scripts/jquery-1.4.1-vsdoc.js" />
    <asp:ScriptReference Path="~/Scripts/jquery-ui-1.8.2.custom.min.js" />
  </Scripts>
</asp:ScriptManager>

content page:

<div id="tabs">
    <div id="whatWorkedWellDiv">
        <fieldset>
            <legend>What Worked Well</legend>
            <br />
            <label for="user">
                Name</label>
            <input type="text" name="user" value="" /><br />
            <label for="emailaddress">
                Email Address:</label>
            <input type="text" name="emailaddress" value="" /><br />
            <label for="comments">
                Comments:</label>
            <textarea name="comments"></textarea><br />
            <label for="terms">
                Agree to Terms?</label>
            <input type="checkbox" name="terms" class="boxes" /><br />
            <input type="submit" name="submitbutton" id="submitbutton" value="Submit" />
        </fieldset>
    </div>
    <div id="whatCouldHaveGoneBetterDiv">
        <fieldset>
            <legend>What could have gone better</legend>
            <br />
            <label for="user">
                Name</label>
            <input type="text" name="user" value="" /><br />
            <label for="emailaddress">
                Email Address:</label>
            <input type="text" name="emailaddress" value="" /><br />
            <label for="comments">
                Comments:</label>
            <textarea name="comments"></textarea><br />
            <label for="terms">
                Agree to Terms?</label>
            <input type="checkbox" name="terms" class="boxes" /><br />
            <input type="submit" name="submitbutton" id="submit1" value="Submit" />
        </fieldset>
    </div>
</div>

Jscript:

$(document).ready(function () { $("#tabs").tabs(); });
+1  A: 

If you are using frames/iframes this may be possible, since the .ready() handler would fire on that DOM in which it is actually executed.

Another way this could happen is, if you 'afterload' some parts of your site asyncronous.

Whatsoever, if you have different DOMs in your site, you need an individual .ready() handler in all of them.

If you don't have any of those constelations, please provide your html markup.

jAndy
I have updated my question with the markup.I am not doing any dynamic loading or frames/iframes...
Vladimir Georgiev
@Vladimir: where do you insert your javascript ? Did you try to do a simple `alert()` within `.ready()` or access a DOM element ?
jAndy
@jAndy: the javascript is inserted in a separate file.The problem is that the document ready is executed when the master page is loaded, not when the content page is loaded.
Vladimir Georgiev
@Vladimir - Are you using an UpdatePanel? To the client there is no idea of a master page, it's just one big chunk of HTML sent down, regardless of how the server assembles it.
Nick Craver
Well, it appears that the jquery call must be placed after all the divs in the content page.
Vladimir Georgiev
A: 

Try the following in your MasterPage

<script language="javascript" type="text/javascript" src='<%=ResolveClientUrl("~/Scripts/jquery-1.4.2.min.js")%>'></script> 
ajai