views:

30

answers:

2

I'm trying to do a String.Replace inside my asp:image tag (nested in a Repeater) in order to change an apostrophe to an html friendly apostrophe

<asp:Image ID="Image1" 
           runat="server" 
           ImageUrl='<%# String.Format("~/images/products/{0}", XPath("image"))%>' 
           Visible='<%# CheckEmpty(XPath("image")) %>' 
           AlternateText='<%# XPath("@name")%>' 
           ToolTip='<%# XPath("@name").Replace("'", "&apos;")%>' />

The "ToolTip" is giving me difficulties. The error says "not well formed" but I know it's something to do with the format but.

A: 
Protected Function ReplaceApostrophe(ByVal input As String) As String
    Return input.Replace("'", "&#39;")
End Function

<asp:Image ID="Image1" 
           runat="server" 
           ImageUrl='<%# String.Format("~/images/products/{0}", XPath("image"))%>' 
           Visible='<%# CheckEmpty(XPath("image")) %>' 
           AlternateText='<%# XPath("@name")%>' 
           ToolTip='<%# ReplaceApostrophe(XPath("@name"))%>' />
rockinthesixstring
+1  A: 

You should probably use HtmlEncode since it's already included in the framework:

ToolTip='<%# HttpUtility.HtmlEncode(XPath("@name")) %>'
Payton Byrd