我正在开发一个使用大量 JavaScript 和 CSS 的 ASP.NET 自定义控件。出于维护目的,将文件分开更容易。在我声明我的命名空间之前,我有以下代码:
[assembly: WebResource("MyNamespace.Styles.colorbox.css", "text/css", PerformSubstitution = true)]
[assembly: WebResource("MyNamespace.Styles.pagination.css", "text/css")]
CSS 文件显然位于名为 Styles 的子文件夹中。我正在尝试使用以下代码在我的页面的 OnInit 中注册它们:
// Register colorbox css
cssColorbox = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(typeof(DoctypeSelectorControl), "MyNamespace.Styles.colorbox.css") + "\" type=\"text/css\" rel=\"stylesheet\" />";
this.Page.ClientScript.RegisterClientScriptBlock(typeof(DoctypeSelectorControl), "cssFile", cssColorbox, false);
// Register pagination css
cssPagination = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(typeof(DoctypeSelectorControl), "MyNamespace.Styles.pagination.css") + "\" type=\"text/css\" rel=\"stylesheet\" />";
this.Page.ClientScript.RegisterClientScriptBlock(typeof(DoctypeSelectorControl), "cssFile", cssPagination, false);
第一个加载完美,但我什至没有看到第二个(pagination.css)的链接。我不确定这是否仅限于一个文件,或者是否有更好的方法来处理这个问题。
仅供参考:如果不明显,DoctypeSelectorControl 是类的名称。
谢谢你的帮助!