Server.HtmlDecode Question

Discussion in 'ASP .Net' started by Night Air, Jan 5, 2008.

  1. Night Air

    Night Air Guest

    I'm trying to put an image tag inside of an anchor tag that I plan to
    dynamically add to a place holder tag.

    The trouble is, though, that the "<" character is showing as "&lt;" and the
    ">" as "&gt;". Is there a way to get these show correctly on the html page?

    Thanks in advance!

    C# Code
    System.Web.UI.HtmlControls.HtmlAnchor hMenuHome = new HtmlAnchor();
    hMenuHome.ID = "hMenuHome";
    hMenuHome.HRef = "default.aspx";
    hMenuHome.InnerText = Server.HtmlDecode("&lt;") + "img name=\"n_home\"
    src=\"images/n_home.gif\" width=\"202\" height=\"50\" border=\"0\"
    id=\"n_home\" alt=\"Home\" /" + Server.HtmlDecode("&gt;");
    hMenuHome.Attributes["onMouseOut"] = "MM_swapImgRestore();";
    hMenuHome.Attributes["onMouseOver"] =
    "MM_swapImage('n_home','','images/n_home_f2.gif',1);";
    phMenuHome.Controls.Add (hMenuHome);

    Resulting Html Code
    <a href="default.aspx" id="hMenuHome" onMouseOut="MM_swapImgRestore();"
    onMouseOver="MM_swapImage('n_home','','images/n_home_f2.gif',1);">&lt;img
    name=&quot;n_home&quot; src=&quot;images/n_home.gif&quot;
    width=&quot;202&quot; height=&quot;50&quot; border=&quot;0&quot;
    id=&quot;n_home&quot; alt=&quot;Home&quot; /&gt;</a>
     
    Night Air, Jan 5, 2008
    #1
    1. Advertisements

  2. Night Air

    Night Air Guest

    Nevermind -- I found the problem.

    I was using InnerText instead of InnerHtml.

    Problem solved.

    Thanks anyway!
     
    Night Air, Jan 6, 2008
    #2
    1. Advertisements

  3. Yes, and for information Server.HtmlDecode("<") will not produce
    anything good.
    For html decoding you have to put HTML in it. And "<" by its own is
    not HTML
     
    jordan.houari, Jan 16, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.