我已经非常努力地在我的 WebPart 中包含一个 JavaScript 文件作为资源。Web 部件类和 flexidgrid.js 文件都位于项目的根级别。Web 部件在 DisplaySearchResults.js 中创建:
namespace DisplaySearchResults
{
public class DisplaySearchResults : WebPart
{
### Hidden Irrelevant Stuff Here ###
protected override void CreateChildControls()
{
### Hidden Irrelevant Stuff Here ###
### Load JavaScript Code Here ###
string scriptURL = Page.ClientScript.GetWebResourceUrl(typeof(DisplaySearchResults), "DisplaySearchResults.flexigrid.js");
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsClientScriptBlockRegistered(ByeByeIncludeScriptKey))
cs.RegisterClientScriptInclude(this.GetType(), ByeByeIncludeScriptKey, scriptURL);
}
### Hidden Irrelevant Stuff Here ###
}
}
DisplaySearchResults 的 AssemblyInfo.cs 如下所示:
[assembly: WebResource("DisplaySearchResults.flexigrid.js", "text/javascript")]
但由于某种原因,WebResource.axd 文件仍然显示为 404。