Mayfield Global Knowledge Center



I am utilizing master pages in my ASP.NET AJAX enabled web site. How do I load my custom JavaScript files when needed?

If you are using ASP.NET 2.0 master pages and utilizing ASP.NET AJAX framework, you may want to include the ScriptManager control on your master page instead of on individual pages. However when referencing other JavaScript files, you may run into problems. You would also need to reference all the files that you will use within the pages, even on those that that do not utilize these files.

 There can only be one ScriptManager control per page.

To add JavaScript files to pages when necessary, add the ScriptManagerProxy control: <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="MyJavaScriptFile.js" />
    </Scripts>
</asp:ScriptManagerProxy>

The ScriptManagerProxy control provides ScriptManager functionality when there is already another ScriptManager present.

Would you like to...


del.icio.us

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favoritesAdd to favorites

User Opinions (18 votes)

88% thumbs up 11% thumbs down

How would you rate this answer?

Helpful
Not helpful
Thank you for rating this answer.

Visitor Comments

  1. Comment #1 (Posted by Hi )
    in master pages javascript not run if we not used resolveurlfunction please reffer following code <script type='text/javascript' src='<%= ResolveUrl ("~/MyScript/script3.js") %>'></script> use this code & edit file exact path exactly or try instead of path use src attribute

Related Questions

Attachments

No attachments were found.