Preferred method for referencing stylesheets from UserControl?

First of all, we use the ASP.NET environment. Now I am creating an application that uses “Modules”, which is just a UserControl, with its “Javascript” on the right side of the control and the link to the stylesheet for this control. I want to keep it modular and would like the style of this control to be independent of markup / javascript.

So, I am wondering what is the preferred way to do this? Obviously, if I don't need the "theme" functionality that I will, I can just use the style tags at the top of the control. Right now I have a link element, as I said, and this is wrong, I don’t think.

Does anyone have any preferred methods, and if so, what and why?


I briefly covered ASP.NET topics, but the idea of ​​these controls is a little different, I think.

This is mainly a shopping cart system. I do not want to delve into all this, but we use a very neat security system, and we do not want to use a shopping cart. I am developing a set of controls that can be deleted on a page, for example, in SiteFinity (which we use in the CMS system) or for any other project that we may have. I usually collected them in a DLL, so we get ACTUAL controls that we can drag from the toolbar, then I could use the internal “general” style and allow any additive style that someone might want, as well as provide some more attractive styles, good.

, - , , - , , . , , , , .


, , "", CSS jQuery. , Theme usercontrol, .

, javascript ScriptBlock , script .

, DebugBar IE, , div. , , , , css, . "" THAT , _Load UserControl, .

@import, , , , ?

+3
4

, ... ASP.NET?

, CssFriendly project. ( , , , .) .css Embedded Resource, .

string filePath = page.ClientScript.GetWebResourceUrl(type, css);

// if filePath is not empty, embedded CSS exists -- register it
if (!String.IsNullOrEmpty(filePath))
{
    if (!Helpers.HeadContainsLinkHref(page, filePath))
    {
        HtmlLink link = new HtmlLink();
        link.Href = page.ResolveUrl(filePath);
        link.Attributes["type"] = "text/css";
        link.Attributes["rel"] = "stylesheet";
        page.Header.Controls.Add(link);
    }
}
+2

, Page.RegisterScriptBlock script. ascx script. , .

. , , . , .

+2

, , , .

.skin, , .

, , css ( - PITA css).

CssClass .

+1

, import.css - , , .

"30DayPricingCalc", /id:

30DayPricingCalc.css

.30daypricingcalc_main_content
{
  ...
}

, , , . .

, , . IE5 , IE6 @import.

!

+1

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


All Articles