Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem placing ContentPlaceHolder within <script> tags

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.

like image 628
rism Avatar asked Jan 31 '26 00:01

rism


2 Answers

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>"%>
like image 82
Ascher Avatar answered Feb 02 '26 14:02

Ascher


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.

like image 39
intermension Avatar answered Feb 02 '26 15:02

intermension



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!