Response.write doesn't display the image - asp.net

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

<%= %> 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'/>";

Try this
<% Response.Write("<img alt='' src='" +
VirtualPathUtility.ToAbsolute("~/Content/images/txt2.png") +
"' border='0'/>" ); %>

Related

Pass Variable from Content page to Master Page in classic ASP

I am new to classic ASP and I am trying to create a Master Page with variable placeholders and fill the information on that page with variables that are worked on a content page.
my master page looks like this:
<html>
<head>
<title>Template Loaded Properly</title>
</head>
<body>
<% call BodyContent %>
<span>Title: <% //place title here %></span>
<span>Content: <% //place content here %></span>
</body>
</html>
and the content page like this:
<!--#include virtual="/templates/TEMPLATE.html" -->
<% sub BodyContent %>
var Title = "This is the title"
var Content = "Here goes some content"
<% end sub %>
Any help will be appreciated.
Once you include the page with the variables, you can treat them as if they were created right then and there (because in a sense they are created right then and there, at least from the server's point of view). You do need to make the variables global in scope [read: dim them outside the sub], unless you want to list all of them when calling your BodyContent sub. (Personally, I don't see the point, but some people are unreasonably allergic to global variables.)
<%
dim Title, Content
sub BodyContent
Title = "This is the title"
Content = "Here goes some content"
end sub
%>
<body>
<% call BodyContent %>
<span>Title: <%=Title%></span>
<span>Content: <%=Content%></span>
</body>
One caveat, though: include files are processed long before the code, so you can't vary what file is included. In other words, don't do this:
<%If x = a Then%>
<!-- #include virtual="/templateA.inc" -->
<%Else%>
<!-- #include virtual="/templateB.inc" -->
<%End If%>
The result of trying something like that is that both templateA and templateB will be included. If you need conditional includes, look into using FileSystemObject to read the content of the appropriate template, and then using Execute to, well, execute it.

change frames/iframes to just one page #aspclassic

How do I rewrite the following PHP code in Classic ASP?
<head></head>
<body>
<h1>Test</h1>
<section><?php echo include('content/'.$_GET['p'].'.php') ?></section></body>
If the url is http://foo.bar.com/admin.php?p=pages, then content/pages.php is shown.
You can't do this with INCLUDE but you could use Server.Transfer instead, eg.
Server.Transfer "content/" & Request.Form("p") & ".asp"
Never trust what comes from the clientside (browser) as they can try to hack you.
Since it is not likely that "shdyhio3hlkehio.asp" or similar is a proper file, you should limit the options to your actual selection and also have a default file which is a "catch all other requests".
Combine that with Server Side Includes and you have your setup ready.
You should also check if the user actually requested a page -- if "p" is empty then show a default message.
Note the use of LCase in the "Select Case"-line and lowercase values in the Case-lines.
This is due to the face that the string comparison is case-sensitive, meaning "about" (lowercase "a") and "About" (uppercase "A") is not the same.
Eksemple:
<% If Request.QueryString("p") = "" Then %>
no specific page was request, show a default message
<% Else %>
<% Select Case LCase(Request.QueryString("p")) %>
<% Case "content" %><!-- #include file="content.asp" -->
<% Case "about" %><!-- #include file="about.asp" -->
<% Case "contact" %><!-- #include file="contact.asp" -->
<% Case Else %><!-- #include file="404.asp" -->
<% End Select %>
<% End If %>
You can use something like this
<!--#include file="somefile.asp"-->
in your HTML file .

Dynamically change Facebook share thumbnail in ASP .Net

I used Facebook like button in ASP .Net my web site master page and when sharing page link in Facebook. I want to change the thumbnail attach with link to each pages, I get image url back end of my asp website and assign to variable and when I'm trying to bind it to front end as below it doesn't get actual value
<link rel="image_src" type="image/jpeg" href=" <% = ImgLink %>"/>
(ImgLink is dynamic variable I got from my back end of code ) at least it doesn't suggest in visual studio.
Try
<asp:PlaceHolder runat="server">
<link rel="image_src" type="image/jpeg" <%= "href='" + ImgLink + "'"%>/>
</asp:Placeholder>
Here is a detailed explanation why this is working.
LitFacebook.Text = "<a name=\"fb_share\" type=\"button\" share_url =\"http://kidstrail.inoday.co.in/\"></a>" +
"<script " +
"src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " +
"type=\"text/javascript\"></script>";
On Design Page, Take a Literal control:
<div style="float:left; height:18px; margin-left:3px; overflow:hidden;"><asp:Literal ID="LitFacebook" runat="server" ></asp:Literal> </div>

Classic ASP showing variable

I just want to show a result of a variable on a page and i am struggling
heres my code, the variable is in a table as you can see
thanks in advance
<tr><td><%
Dim sTest
sTest = "Monkey"
Response.Write("<p>" & sTest & "</p>")
%>
<p> This is Excel </p>
</td></tr>
Save the below code as HelloWorld.asp. Open this page in a web browser. Tell us what you see.
(Don't put any html code or anything else)
<%
Dim sTest
sTest = "Hello World"
Response.Write(sTest)
Response.End
%>
html code....
<p><%=sTest%></p>
html code....
I tried your code in a .asp file and it seems to be working... What problem are you facing? I have added border=1 to your code to show the table border...
<html> <body>
<%
Dim sTest
sTest= "TEXT"
response.write("<table border='1'><tr><td>")
response.write (sTest)
response.write ("</td></tr></table>")
%>
</body> </html>
I don't understant exactly your code (This is Excel? ,/tr>? ) but:
<%
Dim sTest
sTest= "TEXT"
response.write "<table><tr><td>"
response.write sTest
response.write "</td></tr></table>"
%>
Will write "TEXT" in the only cell of the table.
EDIT: He was using .htm as file extension.

Escaping inline code block in Asp.Net template

I have a page where I wish to render the following html (a small JS template)-
<script type="text/html" id="lightbox-template">
<div id="lightbox-background"></div>
<div id="lightbox"><%= content %><div class="bottom"></div></div>
</script>
However, the Asp.NET preprocessor is picking up on the "<%=" tag and trying to interpret it. I wish to escape this tag to allow it to be rendered, preferably from the template rather than the code behind. Is this possible?
I have managed to do this via a Literal control and setting it's text in the code behind.
I ideally wanted to keep it within the aspx page. This is the best solution I could find (from here), which creates splits the closing > into a separate string
<script type="text/html" id="lightbox-template">
<div id="lightbox-background"></div>
<div id="lightbox"><%= "<%= content %" + ">" %=><div class="bottom"></div></div>
</script>
Important bit: <%= "<%= content %" + ">" %=>
This goes into aspx
<div> <%= GetContentString() %> </div>
This goes into aspx.cs
protected String GetContentString()
{
return "this is a content";
}

Resources