img标签使用资源文件和ASP:字面上 [英] img tag with Resource Files and asp:literal

查看:268
本文介绍了img标签使用资源文件和ASP:字面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,我似乎无法修复。我使用的WebForms和.NET 4.5。

I am having a weird issue that I can't seem to fix. I am using WebForms and .NET 4.5.

我有一堆在图像文件夹的图像在我的根目录下。这些图像分别对应于一些局部一个文件夹中。它看起来是这样的。

I have a bunch of Images in an Images folder in my root directory. These images are each in a folder corresponding to some local. It looks like this.

Root

    -Images

        -en-US

            -flag.jpg

        -es-MX

            -flag.jpg

我使用资源文件来存储图像路径。

I am using resource files to store the image paths.

现在的实际问题是,我不能确定如何使用相对路径与资源文件一起定义IMG SRC。通常情况下我可以把=服务器中的img标签和它可以让我指定的src =〜/ somepath但由于我使用的文字一个asp作为源的一部分,它似乎并没有跨preT标签不。正确如果我不使用〜(根),资源不会立即加载在用户更改页面,是不是在根目录下,因为它试图根据新的位置加载它,例如:someurl /UserPages/Images/flag.jpg< =应someurl /图片/ Flag.jpg

Now the actual issue is that I am unsure how to use relative paths to define the img src in conjunction with the resource file. Normally I could put runat="server" in the img tag and that would let me specify src="~/somepath but since I am using an asp literal as part of the source it does not seem to interpret the tag correctly. If I don't use the ~ (root), the resource wont load as soon as the user changes to a page that is not in the root directory because it tries to load it based on the new location. For example: someurl/UserPages/Images/flag.jpg <= should be someurl/Images/Flag.jpg.

下面是我的img标签的样子:

Here is what my img tag looks like:

<img src="~/Images/<asp:Literal ID="test" meta:resourcekey="test" runat="server" Text="" />" runat="server" alt="Flag" height="42" width="42" />

这并不在所有的工作,因为它除$ P $点的路径

That does not work at all because it interprets the path as

http://ipaddr:port/~/Images/

我曾尝试使用jQuery设置img标签的src实现此,并没有解决问题。

I have tried implementing this using jQuery to set the src of the img tag and it did not fix the problem.

这是一些我曾尝试使用来解决我的问题,但没有成功的知识库文章。

These are some of the KB articles I have tried to use to fix my problem with no success.

http://msdn.microsoft.com/en-us/magazine/ cc163566.aspx

HTML IMG和ASP.NET的图像和相对路径

如何使用图像资源在asp.net网站?

http://forums.asp.net/t/1677822.aspx/1

在asp.net 图像定位

在此先感谢您的帮助,你可以给。

Thanks in advance for any help you can give.

编辑:

我试图把图像资源文件本身,而是一些挖后,我发现,这不是Web应用程序很好的解决方案。还是坚持我原来的问题。 (

I tried putting images in the resource file itself but after some digging I found that this is not a good solution for web applications. Still stuck with my original problem. :(

仍然没有运气!

推荐答案

可以解决这个问题是这样的:

You can solve it like this:

your_asp_literal.Text = "<img src='"+ GetGlobalResourceObject("your_resx_file", "your_picture_path").ToString() + "' alt='your_alt' height='42' width='42'/>";

这篇关于img标签使用资源文件和ASP:字面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆