views:

173

answers:

3

I have this in an ASP.Net Master Page:

 <script language="javascript" type="text/javascript">
        <asp:ContentPlaceHolder ID="scriptContentHolder" runat="server"></asp:ContentPlaceHolder>
    </script>

But when I try to view the content page in design mode it tells me there is an error in the associated Master page because "scriptContentHolder" does not exist.

<asp:Content ID="scriptContent" ContentPlaceHolderID="scriptContentHolder" runat="server">
    g_page = "mnuSurveys";
</asp:Content>

If I change the Master page to this:

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

and the content page to this:

<asp:Content ID="scriptContent" ContentPlaceHolderID="scriptContentHolder" runat="server">
<script language="javascript" type="text/javascript">
    g_page = "mnuSurveys";   
    </script>
</asp:Content>

Then all is cool. Why is this? The page compiles and executes just fine... but as above the designer squawks when placing ContentPlaceHolder controls within tags.

+1  A: 

According to this MS Connect posting as of May '09, the

VS designer doesn't support controls within script blocks. Alternately, you can call Page.ClientScriptManager.RegistgerClientScriptBlock from content page

[sic]

So you'll have to use the second/work around method you posted.

intermension
Or the `RegisterScriptBlock` method mentioned in the quote.
Jørn Schou-Rode
A: 

I had the same problem and solved it like that:

<%= "<script type=\"text/javascript\">" %>    
    jQuery(document).ready(function() {
        // On document ready, execute this methods... 
        <asp:ContentPlaceHolder ID="jQueryOnDocReady" runat="server" />                 
    });
<%= "</script>"%>
Ascher
A: 

this may be a bit off track. But I was having the same issue because i had some generic code i wanted in my Master page, and other more specific only on certain pages, here is my solution:

-In my .Master:

<script type="text/javascript">
     var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
    _gaq.push(['_trackPageview']);
</script>

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

-In my .aspx:

<asp:Content ID="Content1" ContentPlaceHolderID="PerPageScript" runat="server">
    <script type="text/javascript">
    ...
    </script>
</asp:Content>
mcbros