1

The following code does not work:

literalNews.Text = "<img id='Image3' src='~/images/news_li.gif' alt=' ' height='20' width='20' />"; 
3
  • Bind an image tag inside the literal <a id='img' src='[path]'></a>. Thats it! Commented Sep 17, 2015 at 6:16
  • 2
    What you have won't work as '~/images/etc needs to have the path resolved. Commented Sep 17, 2015 at 6:50
  • what Jon P means is that you could try to remove the '~' from '~/images/news_li.gif' Commented Sep 17, 2015 at 6:56

2 Answers 2

2

Assuming that your context is a page you need to resolve ~/ as it is a .net construct, it enables code to be used at different levels of a website.

Try

string src = Page.ResolveUrl("~/images/news_li.gif"); 
literalNews.Text = string.Format("<img id='Image3' src='{0}' alt=' ' height='20' width='20' />", src);

Your other option is to use a root relative path

literalNews.Text = "<img id='Image3' src='/images/news_li.gif' alt=' ' height='20' width='20' />";
Sign up to request clarification or add additional context in comments.

Comments

1

Try this, this works fine on me.. :)

literalNews.Text = "<img id='Image3' src='../images/news_li.gif' alt=' ' height='20' width='20' />";

Comments

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.