views:

77

answers:

2

I have several partial views with Javascript that I am trying to move to the bottom of the page. To do this I am trying to use a container in the master page

Master Page ->

   <asp:ContentPlaceHolder ID="Foot" runat="server"></asp:ContentPlaceHolder>

Partial view(ascx)

<asp:Content ID="header" ContentPlaceHolderID="head" runat="server">
...
</asp:Content>

But I get this error

Parser Error Message: Content controls have to be top-level controls in a content page or a nested master page that references a master page.

So how do I ensure that the Javascript for the partial view is at the bottom of the page? Especially in cases where the html layout needs to be at the top of the page?

A: 

In your master page:

<body>
    ...
    <asp:ContentPlaceHolder ID="Scripts" runat="server" />
</body>

And in the page (aspx) that uses the partial (ascx):

<asp:Content ID="indexScripts" ContentPlaceHolderID="Scripts" runat="server">

    <script type="text/javascript">
    ...
    </script>

</asp:Content>
Darin Dimitrov
This is suboptimal since I then have to also include the scripts tag in each page that references the partial view.
Kenoyer130
A: 

The best approach is to use nested master pages instead of user controls.

Kenoyer130