Reputation: 955
Writing html using Response.Write in asp.net it doesn't display the image. I check my image path code and simple put it in the page and it works fine. Why it doesn't display the image when writing using response.write code. Following is my image path code
<img alt="" src="<%= VirtualPathUtility.ToAbsolute("~/Content/images/txt2.png")%>" border="0"/>
This is Response.write code
<% Response.Write(valueHelp); %>
ValueHelp is a string which contain the image code which i have mention above.
Any idea why it is not working? Thanks in advance
Upvotes: 0
Views: 1275
Reputation: 19953
<%= %>
is to be used within the mark-up (i.e. the HTML part of your code) and not in the code-behind.
My guess (without seeing the code) is that you are actually sending <%= VirtualPathUtility.ToAbsolute("~/Content/images/txt2.png")%>
to the browser as part of a static string.
So instead of it being picked up by the server and rendered into the correct path, it is simply being sent as part of the HTML to the browser (the browser not knowing what on earth it means, therefore it will not show the image you expect).
Try something like this when you are creating the valueHelp
string
valueHelp = "<img alt='' src='" + VirtualPathUtility.ToAbsolute("~/Content/images/txt2.png") + "' border='0'/>";
Upvotes: 2
Reputation: 19591
Try this
<% Response.Write("<img alt='' src='" +
VirtualPathUtility.ToAbsolute("~/Content/images/txt2.png") +
"' border='0'/>" ); %>
Upvotes: 1