简体   繁体   中英

referencing a jquery library from code behind

Is there a way I can reference a jquery library from code behind , in the master page.

This is because I only want to use jquery on aspx pages that need to use them. Currently I have my jquery reference in the form tag and it gets loaded on every page load.

<body>
    <form id="form2" runat="server">
    <asp:ScriptManager ID="ScriptManagerService" runat="server">
        <Scripts>
            <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ScriptMode="Auto" />
            <asp:ScriptReference Path="http://code.jquery.com/jquery-migrate-1.2.1.js" ScriptMode="Auto" />
            <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" ScriptMode="Auto" />
        </Scripts>
    </asp:ScriptManager>
    </form>
</body>

If you just want to reference external JS file in content pages, you can use ScriptManagerProxy control. It will act pretty much like ScriptManager, but won't confilct with ScriptManager of the Master Page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM