admin管理员组

文章数量:1434966

I use asp script manager in master page to add js files . In one of child pages i dont want specific js file to be excluded . is it possible in asp?

eg code in my master page

    <asp:ScriptManager runat="server" EnablePageMethods="true"  EnablePartialRendering="true" ID="id" OnResolveScriptReference="sm_ResolveScriptReference">
    <Scripts>
        <asp:ScriptReference Path="~/scripts/jquery-1.4.2.min.js" /> 
         <asp:ScriptReference Path="~/scripts/jquery.bgiframe.min.js" />
        <asp:ScriptReference Path="~/scripts/tax.js" />
        <asp:ScriptReference Path="~/scripts/old.js" />
        <asp:ScriptReference Path="~/scripts/menu.js" />
    </Scripts>
</asp:ScriptManager>

i like to exclude old.js from one child page.Hope this helps

I use asp script manager in master page to add js files . In one of child pages i dont want specific js file to be excluded . is it possible in asp?

eg code in my master page

    <asp:ScriptManager runat="server" EnablePageMethods="true"  EnablePartialRendering="true" ID="id" OnResolveScriptReference="sm_ResolveScriptReference">
    <Scripts>
        <asp:ScriptReference Path="~/scripts/jquery-1.4.2.min.js" /> 
         <asp:ScriptReference Path="~/scripts/jquery.bgiframe.min.js" />
        <asp:ScriptReference Path="~/scripts/tax.js" />
        <asp:ScriptReference Path="~/scripts/old.js" />
        <asp:ScriptReference Path="~/scripts/menu.js" />
    </Scripts>
</asp:ScriptManager>

i like to exclude old.js from one child page.Hope this helps

Share Improve this question edited Jul 3, 2012 at 13:37 Bumble asked Jul 3, 2012 at 13:28 BumbleBumble 5573 gold badges10 silver badges24 bronze badges 1
  • And what's your concern over including old.js in this child page? Does it conflict with any other js code or it's just because you think it's inefficient? – Icarus Commented Jul 3, 2012 at 13:43
Add a ment  | 

2 Answers 2

Reset to default 4

Warp your ScriptManager inside a PlaceHolder and when you do need to change it simple include this PlaceHolder on the child. Eg:

 <asp:ContentPlaceHolder id="ScrMang" runat="server">        
     <asp:ScriptManager runat="server" EnablePageMethods="true"  EnablePartialRendering="true" ID="id" OnResolveScriptReference="sm_ResolveScriptReference">
    <Scripts>
        <asp:ScriptReference Path="~/scripts/jquery-1.4.2.min.js" /> 
         <asp:ScriptReference Path="~/scripts/jquery.bgiframe.min.js" />
        <asp:ScriptReference Path="~/scripts/tax.js" />
        <asp:ScriptReference Path="~/scripts/old.js" />
        <asp:ScriptReference Path="~/scripts/menu.js" />
    </Scripts>
     </asp:ScriptManager>       
   </asp:ContentPlaceHolder>

and on child if you include this line it will remove the ScriptManager. Of course you can include it again with different script to load.

<asp:Content ID="Content3" ContentPlaceHolderID="ScrMang" Runat="Server">
</asp:Content>

Second solution is to make nested master page in the same way, include the ScriptManager inside a PlaceHolder, make a MasterPage with the first as parent, and change the script that it will include. Then select what page get the master page, and what gets the nested master page with different scripts.

Master Pages can include default content in tags. When the master page is used by the sub-page and does not include a reference to the content placeholder that has default content, the default content is rendered in its place.

What I would do in this instance is create a content placeholder for my scripts in the master page. Then, in the page that you don't want to have the script show up, create a content item pointing to the with your scripts. This allows you to 'override' the scripts that are used on that specific page.

本文标签: javascriptexclude master page js file in aspnet child pageStack Overflow