使用 asp.net 资源文件时出错

发布于 2024-07-15 08:57:49 字数 914 浏览 5 评论 0原文

我有一些文本内容,我希望能够在不重新编译项目的情况下进行更改。 我创建了一个资源文件并在其中放入了一些文本内容。

我的印象是我可以写 <%$ Resources:mapLink2 %> 我想要的任何地方,但情况似乎并非如此。

我的 ascx 中的以下代码给了我一个错误:

<a href="<%$ Resources:mapLink2 %>"><img class="2 selectableImg" src="map_2.gif" /></a>

我只收到了瑞典语的错误消息(对此感到抱歉),但我认为它可能会给您一些正在发生的事情的提示:

Literala uttryck som "" är intetilåtna 。 Använd i stället。 vid System.Web.UI.TemplateParser.ProcessError(字符串消息) vid System.Web.UI.TemplateParser.ParseStringInternal(字符串文本,编码文件编码) vid System.Web.UI.TemplateParser.ParseString(字符串文本,VirtualPath virtualPath,编码文件编码)

但如果我这样做:

<a href='<asp:literal runat="server" Text="<%$ Resources:mapLink2 %>"/>'><img class="2 selectableImg" src="map_2.gif" /></a>

一切都会好起来的。

为什么第一个版本不行? 资源文件不应该像我希望的那样在示例 1 中工作吗?

I have som text-content that I want to be able to change without recompiling my project. I have created a resource file and put some text-content in it.

I was under the impression that I could write <%$ Resources:mapLink2 %> wherever I wanted but that doesn't seem to be the case.

The following code in my ascx gives me an error:

<a href="<%$ Resources:mapLink2 %>"><img class="2 selectableImg" src="map_2.gif" /></a>

I only got the error message in Swedish (sorry about that) but I think it might give you some hints of what is going on:

Literala uttryck som "" är inte tillåtna. Använd i stället. vid System.Web.UI.TemplateParser.ProcessError(String message) vid System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) vid System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)

But if I do:

<a href='<asp:literal runat="server" Text="<%$ Resources:mapLink2 %>"/>'><img class="2 selectableImg" src="map_2.gif" /></a>

it all works out allright.

How come the first version doesn't work? Aren't resource files supposed to work like I want them to in example 1?

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

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

发布评论

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

评论(1

纵性 2024-07-22 08:57:49

也许这只适用于服务器控件? 您是否尝试过在第一个示例中的 a 上设置 runat="server" ?

Maybe this only works with server controls? Have you tried setting runat="server" on the a from your first example?

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