Reputation: 61727
Given this webusercontrol:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Comments.ascx.cs" Inherits="Controls_Fresh_Comments" %>
Hello World!
<asp:PlaceHolder runat="server" ID="Javascript">
<script>
alert("Hello!");
</script>
</asp:PlaceHolder>
And this on my master page:
<asp:ContentPlaceHolder runat="server" ID="JSContent"/>
How can I make the Javascript
content in the webusercontrol render into the JSContent
content placeholder?
For good practise and performance, I wish to have control over where the Javascript is rendered on the page. I'm looking for a solution which doesn't require me to modify anything outside of the webusercontrol.
Is this possible?
Upvotes: 3
Views: 132
Reputation: 61727
Doh, just started a bounty then immediately figured it out for myself. On the webusercontrol Page_Load
add the lines:
Page.Master.FindControl("JSContent").Controls.Add(Javascript);
Upvotes: 3