0

I am writing html tags in a an html file by following code in C#:

StringBuilder sbMarquee = new StringBuilder();
sbMarquee.Append("<a href= #  onclick = showimage('Images\\\\Code00005_0001.jpg')>").Append("<img src=Images\\\\thumbnails\\\\Code00005_0001.jpg></img>").Append("</a>");
_hdCaseMarquee.InnerHtml = sbMarquee.ToString();

But, I get following HTML output:

<a href="#" onclick="showimage('Images\\Code00005_0001.jpg')"><img src="Images\\thumbnails\\Code00005_0001.jpg"></a></marquee>

Following tag from the string is completely ignored:

</img>

Please Help

5
  • Try by properly quoting, e.g. Append("<img src=""Images\\\\thumbnails\\\\Code00005_0001.jpg""></img>"). Commented Jun 17, 2013 at 14:18
  • 1
    Always check the contents of your variables in a debugger if you get results you don't expect. If you had, you'd have seen that sbMarquee.ToString() had exactly what you were expecting. Commented Jun 17, 2013 at 14:18
  • @CodeCaster - ' and " are interchangeable for HTML, to the best of my knowledge, so long as you're consistent for each usage. Commented Jun 17, 2013 at 14:19
  • @Bobson but now it says href= # and src={source} without quotes entirely. Anyway see spender's answer. Commented Jun 17, 2013 at 14:25
  • @CodeCaster - Huh, good point. I'd missed that, since the output looked right for that part of it. Commented Jun 17, 2013 at 14:27

1 Answer 1

6

I assume that you're looking at the HTML from the browser, in which case there's a strong likelihood that the closing tag of the img gets gobbled by the HTML parser for the following reason:

img

Tag omission Must have a start tag and must not have an end tag.

Sign up to request clarification or add additional context in comments.

1 Comment

img tags do not require a closing tag in html (but the will require it if using xhtml)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.