Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude master page js file in asp.net child page

I use asp.net 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.net?

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

like image 603
Bumble Avatar asked Jan 23 '26 11:01

Bumble


1 Answers

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.

like image 159
Aristos Avatar answered Jan 26 '26 01:01

Aristos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!