How can I register a css page from an ascx control?

How to register css code code inside ascx control?

Is it possible just

<head id="head" runat="server">
    <style type="text/css">
        .customClass
        {
        background-color: Lime;
        }

        </style>
</head>

Anywhere on the ascx page? I don't seem to work?

+3
source share
3 answers

You have three options for inserting CSS into a page:

  • External style table
  • Internal style sheet
  • Inline style

style head. , , . ( , ) 99,9% .

- ContentPlaceHolder Site.Master head. , ContentPlaceHolder , , link, .

- , .

+5

head HTML. style link, CSS.

head runat="server", this.Page.Header.

, , - <head> </head>, , . URL .

public void AddStylesheet(string url)
{
    string link = String.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />", url);
    this.Page.Header.Controls.Add(new LiteralControl { Text = link });
}
+8
  <style type="text/css">
       @import url(user_stylesheet.css)
       .customClass
        {
            background-color: Lime;
        }

    </style>

In this case, css will only be displayed when rendering usercontrol.

0
source

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


All Articles