简体   繁体   English

在DLL中添加CSS文件(类库)

[英]Add CSS File in DLL (Class Library)

I have a Class Library project named "AddJsFunction" which contains a class where I am including all related JS, CSS and Image files. 我有一个名为“ AddJsFunction”的类库项目,其中包含一个包含所有相关JS,CSS和图像文件的类。 Below is the IncludeJsFile method inside the above mentioned class where I am adding all the Javascript files which works as expected. 下面是上述类中的IncludeJsFile方法,其中我添加了所有按预期工作的Javascript文件。

public void IncludeJsFile(Page pg)
    {
        pg.ClientScript.RegisterClientScriptInclude(this.GetType(), "Test2", pg.ClientScript.GetWebResourceUrl(this.GetType(), "AddJsFunction.queue.js"));
        string csslink2 = "<script type='text/javascript' language='javascript' src='" + pg.ClientScript.GetWebResourceUrl(this.GetType(), "AddJsFunction.queue.js") + "' />";
        LiteralControl include2 = new LiteralControl(csslink2);
        pg.Header.Controls.Add(include2);
    }

Same way I want to embed the CSS files which i tried to include like shown above but that is not working and I need some help to do the same. 我想以同样的方式嵌入我尝试包括的CSS文件,如上所示,但这无法正常工作,我需要一些帮助才能做到这一点。

Thanks, VY. 谢谢,VY。

From Is there a ClientScriptManager.RegisterClientScriptInclude equivalent for CSS : 那里有一个CSS的ClientScriptManager.RegisterClientScriptInclude等效项

HtmlLink link = new HtmlLink();
link.Href = "Cases/EditStyles.css";
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
//check if it exsists on the page header control first
foreach (Control control in pg.Header.Controls)
{
    if ((control is HtmlLink) &&
        (control as HtmlLink).Href == href)
    {
        return true;
    }
}
pg.Header.Controls.Add(link);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM