ASP - 为什么这个img不显示

时间:2012-07-06 15:27:08

标签: asp.net html

以下代码不会显示图像,它会显示图像存在但图像不显示。有什么想法吗?

 <%@ Page Language="C#" MasterPageFile="~/Main_MP.master" AutoEventWireup="true" CodeFile="Phone.aspx.cs"
    Inherits="Phone1" Title="Talk & Txt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<img src="Talk & Txt Page.jpg" alt="Smiley face" height="42" width="42" />

    <br />
<asp:Label ID="lblCounter" runat="server" Visible="False" Font-Bold="True" Font-Names="Calibri" Font-Size="Small" ForeColor="#C00000"></asp:Label></div>
    </div>
</asp:Content>

6 个答案:

答案 0 :(得分:2)

未转义的&符号可能会导致您的问题。

答案 1 :(得分:1)

将图像文件重命名为TalkAndTxtPage.jpg - 所有通过URL链接的文件(包括图像)都是最好的命名,而不使用保留或不安全的字符(空格(“”)和&符号(“&amp;”)适合此类别)。参考 - http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

然后执行此操作(您还有一个错误的<div>标记):

 <%@ Page Language="C#" MasterPageFile="~/Main_MP.master" AutoEventWireup="true" CodeFile="Phone.aspx.cs"
    Inherits="Phone1" Title="Talk & Txt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<img src="TalkAndTxtPage.jpg" alt="Smiley face" height="42" width="42" />

    <br />
<asp:Label ID="lblCounter" runat="server" Visible="False" Font-Bold="True" Font-Names="Calibri" Font-Size="Small" ForeColor="#C00000"></asp:Label>
    <div>
    </div>
</asp:Content>

答案 2 :(得分:0)

用%20替换图像URL(即'src')属性中的空格。

您不能在网址中包含空格,但%20应该有效。

答案 3 :(得分:0)

该图像是否与页面位于同一目录中,否则您需要提供完整的相对路径

答案 4 :(得分:0)

从图像名称中删除空格。

<img src="Talk-Txt-Page.jpg" alt="Smiley face" height="42" width="42" />

此外,图片位于页面的哪个位置?您可能需要指向该目录。

<img src="/images/Talk-Txt-Page.jpg" alt="Smiley face" height="42" width="42" />

希望这有帮助!

答案 5 :(得分:0)

单独使用一张名为Talk&amp;的照片。 Txt Page.jpg适合我。

我在你的代码中看到了几个没有开头div的结尾div标签