我有以下代码,为我为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'被转义为:
“第一行& amp;#013;第二行”
当我在网络浏览器中查看来源时。 (我不得不在上面添加空格,因为这个网站也逃脱了它:)
有没有办法阻止它?
答案 0 :(得分: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类,所以我不确定你会在那里替换它。
答案 1 :(得分:0)
那是因为当它出现在属性引号中时,这是正确的(W3C)方式。我不熟悉您正在使用的确切控件,但请参阅下面的示例:
<img src="img/wrong.jpg" alt="This is the wrong way 
 because the ampersand is not encoded properly for attributes" />
<img src="img/correct.jpg" alt="This is the right way &#013 because the ampersand IS escaped and the browser will read & as just an ampersand plus the code, which is what you want." />