Web 资源是空白页

发布于 2024-08-20 11:43:13 字数 1205 浏览 2 评论 0原文

我有一个自定义控件,其中包含网络资源。

webresource 是一个 javascript 文件,我将 javascript 文件的构建选项设置为“嵌入资源”,并且在我的自定义控件所在项目的 AssemblyInfo.cs 中有以下代码行:

// Export the MultiSelectGridView.js file
[assembly: WebResource("SOM.DCO.CustomWebControls.MultiSelectGridView.js", "application/x-javascript")]

在我的自定义控件中,我在重写的 onload 事件中有以下几行:

private const string MULTISELECTGRIDVIEW_JS = "SOM.DCO.CustomWebControls.MultiSelectGridView.js";
Type t = this.GetType();
                string url = Page.ClientScript.GetWebResourceUrl(t, MULTISELECTGRIDVIEW_JS);
                if (!Page.ClientScript.IsClientScriptIncludeRegistered(t, MULTISELECTGRIDVIEW_JS))
                    Page.ClientScript.RegisterClientScriptInclude(t, MULTISELECTGRIDVIEW_JS, url);

我还尝试了以下操作:

private const string MULTISELECTGRIDVIEW_JS = "SOM.DCO.CustomWebControls.MultiSelectGridView.js";
if (!Page.ClientScript.IsClientScriptIncludeRegistered(t, MULTISELECTGRIDVIEW_JS))
                    Page.ClientScript.RegisterClientScriptResource(t, MULTISELECTGRIDVIEW_JS);

不幸的是,无论我做什么,我得到的网络资源都是空白的,因此我的 javascript 文件中没有包含/定义任何函数我的消费页面。

我错过了一些明显的东西吗?

I have a custom control that has a webresource in it.

The webresource is a javascript file and I have the build option on the javascript file set to "Embedded Resource" and I have the following lines of code in my AssemblyInfo.cs for the project my custom control is in:

// Export the MultiSelectGridView.js file
[assembly: WebResource("SOM.DCO.CustomWebControls.MultiSelectGridView.js", "application/x-javascript")]

In my custom control, I have the following lines in the overriden onload event:

private const string MULTISELECTGRIDVIEW_JS = "SOM.DCO.CustomWebControls.MultiSelectGridView.js";
Type t = this.GetType();
                string url = Page.ClientScript.GetWebResourceUrl(t, MULTISELECTGRIDVIEW_JS);
                if (!Page.ClientScript.IsClientScriptIncludeRegistered(t, MULTISELECTGRIDVIEW_JS))
                    Page.ClientScript.RegisterClientScriptInclude(t, MULTISELECTGRIDVIEW_JS, url);

I've also tried the following:

private const string MULTISELECTGRIDVIEW_JS = "SOM.DCO.CustomWebControls.MultiSelectGridView.js";
if (!Page.ClientScript.IsClientScriptIncludeRegistered(t, MULTISELECTGRIDVIEW_JS))
                    Page.ClientScript.RegisterClientScriptResource(t, MULTISELECTGRIDVIEW_JS);

Unfortunately, no matter what I do, the webresource that I get back is blank, and so none of the functions in my javascript file are included/defined in my consuming page.

Am I missing something obvious?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〃安静 2024-08-27 11:43:13

我刚刚遇到了同样的问题,找出解决方案是一场噩梦。我终于弄清楚了,感谢 此链接。

如果在解决方案资源管理器中右键单击解决方案名称,然后选择“属性”,您将看到“默认命名空间”文本框。

此默认命名空间值必须与您放置在 Web 资源前面的命名空间相同。

因此,如果属性中的默认命名空间仅为“SOM”或仅为“CustomWebControls”,则需要将其更改为“SOM.DCO.CustomWebControls”。

然后在“程序集:WebResource”中使用相同的完整命名空间,并调用 RegisterClientScriptInclude(或 RegisterClientScriptResource,或用于附加 Web 资源的任何方法。

I just had this same issue and it was a nightmare to figure out the fix. I finally figured it out, thanks to this link.

If you right-click on your solution name in Solution Explorer, and choose "properties", you'll see a text box for "Default namespace".

This default namespace value must be the same as the namespace you're putting in front of your web resource.

So, if the default namesspace in your properties is only "SOM" or only "CustomWebControls", you need to change it to "SOM.DCO.CustomWebControls".

Then use that same full namespace in your "assembly: WebResource" and your call to RegisterClientScriptInclude (or RegisterClientScriptResource, or whatever method you're using to attach the web resource.

〃安静 2024-08-27 11:43:13

我过去遇到的唯一问题是在调用 GetWebResourceUrl 时传递了错误的 Type。您必须让 Type 是来自与嵌入式资源相同的程序集的 Type

使用 this.GetType() 可能会出现嵌入资源的问题 (正如 Rick Strahl 所描述的

其他一切对我来说看起来都不错。

The only thing I've had an issue with in the past is passing the wrong Type when calling GetWebResourceUrl. You have to have the Type be a Type that comes from the same Assembly as the Embedded Resource.

Using this.GetType() can present problems embedding resources (as described by Rick Strahl)

Everything else looks ok to me.

泪冰清 2024-08-27 11:43:13

事实证明,尽管我的 javascript 位于“命名空间”SOM.DCO.CustomWebControls 中,但它位于名为“MultiSelectGridView”的文件夹中。
因此,我将所有对它的引用从 SOM.DCO.CustomWebControls.MultiSelectGridView.js 更改为 SOM.DCO.CustomWebControls.MultiSelectGridView.MultiSelectGridView.js,现在它可以工作了。

Well it turns out that I even though my javascript was in the "namespace" SOM.DCO.CustomWebControls, it was inside a folder called "MultiSelectGridView".
So I changed all the references to it from SOM.DCO.CustomWebControls.MultiSelectGridView.js to SOM.DCO.CustomWebControls.MultiSelectGridView.MultiSelectGridView.js and now it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文