开发者

How do I suppress asp:image AlternateText from html escaping?

开发者 https://www.devze.com 2022-12-28 19:07 出处:网络
I have an asp:Image -- which I\'m assigning \"alt\" and \"tooltip\" from the code behind. Unfortunately the value which is coming from the database is getting automatically html escaped -- which I do

I have an asp:Image -- which I'm assigning "alt" and "tooltip" from the code behind. Unfortunately the value which is coming from the database is getting automatically html escaped -- which I do now want it to -- how do I suppress this?

For example my trademark html entity is doing this -->

® gets changed to --> &#174

-- which is incorrect

开发者_运维技巧

Here's my code in the aspx:

<asp:Image runat="server" ID="MainImage"  Width="260" />

Do I have any options?

Thanks,

-R

And here's my code behind:

this.MainImage.AlternateText = this.BasePage.SellGroup.DisplayName;


I must say that this problem looked simpler than it is. From what I can tell, there is no means to override the Image's default behavior of Html encoding the alt tag. That leaves you with a couple of choices:

Use HttpDecode

Decode your data before you assign the AlternateText attribute. This is probably the simplest and techically since the Image control is encoding the alt attribute, this should work fine. It means that the actual registered symbol will render in the browser instead of &#174;

this.MainImage.AlternateText = HttpUtility.HtmlDecode( this.BasePage.SellGroup.DisplayName );

Use a Literal control

Create a Literal control and set the attribute that way:

this.Literal1.Mode = LiteralMode.PassThrough;
this.Literal1.Text = string.Format( "<img src=\"{0}\" alt=\"{1}\" />", "Foo.jpg", "&#174;" );
0

精彩评论

暂无评论...
验证码 换一张
取 消