How can I register a css code block inside an ascx control?
Can I just have
<head id="head" runat="server">
<style type="text/css">
.customClass
{
background-color: Lime;
}
</style>
</head>
Anywhere in ascx page? I doesn’t seem to work?
You have three options to insert CSS into a page:
The
styleelement must be enclosed within theheadelement. If you are attempting to style elements contained within a user control you can use any of these three options. As a note (mostly my opinion) inline styling is 99.9% of the time the wrong decision.One option is to expose a
ContentPlaceHolderin your Site.Master inside the head section. Then using thisContentPlaceHolderon pages where you use your user control you’ll be able to place alinkelement specifying a style sheet for your user control.Another option is to simply put the styling rules for your user control in the style sheet used for your entire site.