这似乎运作良好:
string imagesScript = String.Format(
"MyNamespace.MyClass.prototype.imgDisabled = '{0}';" +
"MyNamespace.MyClass.prototype.imgEnabled = '{1}';",
Page.ClientScript.GetWebResourceUrl(typeof(MyClass), "MyNamespace.disabled.png"),
Page.ClientScript.GetWebResourceUrl(typeof(MyClass), "MyNamespace.enabled.png")
);
Page.ClientScript.RegisterStartupScript(typeof(MyClass), "Images", imagesScript, true);
然后在我的对象中,我只是做this.imgDisabled或this.imgEnabled获取 URL。
编辑: 另一个选项是AssemblyInfo.cs您将 JavaScript 引用设置为,WebResource(..., PerformSubstitution = true)然后您的 .js 文件可以<%= WebResource("MyNamespace.enabled.png") %>在您希望的任何位置。这可以是您实际使用它或添加到对象原型的地方。