WebResources嵌入式资源和Javascript如何在另一个嵌入式资源中使用它们

WebResources Embedded Resources and Javascript how to use them within another embedded resource?

本文关键字:嵌入式 资源 另一个 Javascript WebResources      更新时间:2023-09-26

我之前也问过类似的问题,但回答很弱,所以不确定我的措辞是否正确。

我目前在一个asp.net页面上有一个自定义的服务器控件。但是,该控件使用完全嵌入的JavaScript和Image资源。我的程序集已经正确设置了所有的网络资源,我一直在成功地使用图像等作为图标。

但是现在,如果可能的话,我想直接在javascript文件中使用嵌入的webresource图像。到目前为止,我已经尝试了以下操作,但没有成功:

document.getElementById('button').src = 'WebResource("NAMESPACE.FOLDER.IMAGE.png")';
document.getElementById('button').src = '<%WebResource("NAMESPACE.FOLDER.IMAGE.png")%>';

我不知道还能尝试什么,因为我的大部分谷歌搜索似乎都走到了死胡同。

提前谢谢。

我相信您正在寻找WebResourceAttribute.PerformanceSubstitution属性:

WebResourceAttribute.在MSDN 上执行替换

我们在定义嵌入式资源的项目中的AssemblyInfo.cs文件中使用它:

[程序集:System.Web.UI.WebResource("","text/css",PerformSubstitution=true)]

编辑:

AssemblyInfo.cs

[assembly: System.Web.UI.WebResource("Project.Content.Styles.css", "text/css", PerformSubstitution = true)]
[assembly: System.Web.UI.WebResource("Project.Images.Sprite.png", "image/png")]

内容/样式.css(嵌入式资源)

.icon {
    background-image: url(<%=WebResource("Project.Images.Sprite.png")%>);
}