Expose ContentPlaceHolder in User Control

I am implementing a web application and I am facing the following problem:

I have a user control with its own styles and js files, when I add a user control to the page and I try to check murkup, I get an error because the user and js styles are in the body of the page instead of the head. I would like for the header page to be added from my web application, the user manages styles and js files directly in the page header. do you have any suggestion? I have not received any good solution on the Internet yet

early

+3
source share
2 answers

css js, :

<asp:PlaceHolder ID="phStyles" runat="server">
  <link type="text/css" rel="stylesheet" href="/App_Themes/Default/style/MyStyles.css" />
</asp:PlaceHolder>

:

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.Controls.Add(phStyles);
    }

, runat = "server" :

<head runat="server">
</head>
+3

. :

HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/javascript");
script.Attributes.Add("src", "/somescript.js");
Page.Header.Controls.Add(script);
+1

Source: https://habr.com/ru/post/1726782/


All Articles