0

我有以下代码为我为 ASP.NET 编写的 Web 应用程序的浏览器提示添加了一个换行符:

RectangleHotSpot rhs = new RectangleHotSpot();
rhs.HotSpotMode = HotSpotMode.Navigate;
rhs.AlternateText = "Line one
Line Two"; //New-line to conform with FF
rhs.NavigateUrl = "my URL";

ImageMap.HotSpots.Add(rhs);

但由于某种原因,“rhs.AlternateText”被转义为:

“第一行
第二行”

当我在网络浏览器中查看源代码时。(我不得不在上面添加空格,因为这个网站也逃脱了它:)

有什么办法可以防止这种情况发生吗?

4

2 回答 2

1

尝试这样的事情:

    public class RectangleHotSpot : System.Web.UI.WebControls.HotSpot
{
    private string _strAlt;
    public override string AlternateText
    {
        get
        {
            return _strAlt;
        }
        set
        {
            this._strAlt = value;
        }
    }

    public override string GetCoordinates()
    {
        return String.Empty; // You'll need to fill this in.
    }

    protected override string MarkupName
    {
        get { return String.Empty; } // This too.
    }
}

GetCoordinates 和 MarkupName 作为抽象成员的一部分是必需的,但我不熟悉 Rectangle Hot Spot 类,所以我不确定你会在那里替换什么。

于 2012-09-30T03:26:18.653 回答
0

这是因为当它出现在属性引号中时,这是使用它的正确 (W3C) 方式。我不熟悉您使用的确切控件,但请参见下面的示例:

<img src="img/wrong.jpg" alt="This is the wrong way &#013; because the ampersand is not encoded properly for attributes" />

<img src="img/correct.jpg" alt="This is the right way &amp;#013 because the ampersand IS escaped and the browser will read &amp; as just an ampersand plus the code, which is what you want." />
于 2012-09-30T00:48:07.417 回答