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.
Related
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.
I've an asp page that has to check are large database, takes about 4 seconds
I'm trying to use Response.Buffer to show a "Please Wait" then display the result of the database search. Then remove the "Please Wait"
No matter where a place the Buffer = True and Flush I just get a blank page until the result is displayed.
Here's the latest attempt:
<% Response.Buffer = True 'Top of page' %>
<html>
Please Wait....
<% Database search %>
<% Remove please wait %>
<% Response.Flush %>
Display results
</html>
Thanks in advance
John
Through trial and error I've got there
Response.Flush straight after the "Please Wait"
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 .
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'/>" ); %>
I am trying to separate some asp logic out into a separate page.
For now, I am trying to call a simple function.
Here is the simple index page that I am using
<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
%>
<!--#include file="aspFunctions.asp"-->
<%
doStuff()
End If
%>
<FORM method=POST name="form1" ID="Form1">
ID:
<INPUT type="text" name="corpId" ID="id" value="050893">
<BR><BR>
<INPUT type="submit" value="GO" name="submit1" ID="Submit1" >
</form>
</body>
</html>
Here is aspfunctions.asp
sub doStuff()
Response.Write("In Do Stuff")
end sub
When i hit the submit button on my form i get the below
sub doStuff() Response.Write("In Do Stuff") end sub
Microsoft VBScript runtime error '800a000d'
Does anyone have any idea what i could be doing wrong?
Any help is greatly appreciated
Thanks
Damien
Type mismatch: 'doStuff'
/uat/damien/index.asp, line 15
You must have the asp functions inside the <% %> tag.
aspfunctions.asp should be inside tags so the asp is "executed", e.g.
aspfunctions.asp file:
<%
sub doStuff()
Response.Write("In Do Stuff")
end sub
%>
Otherwise the asp in aspfunctions.asp is just seen as plain-text, so as far as the server is concerned, doStuff has never been defined.
You're including the other file within an if statement. This does not mean that it's dynamically included, it's not. It will always be included.
To see this in action try this sample:
<%
If 1=0 Then
'We never get here
%>
<!--#include file="aspFunctions.asp"-->
<%
dostuff()
End If
dostuff()
%>
If I remember correctly, you need no brackets for calls without a return value (untested solution):
doStuff
Make changes in two places:
In aspfunctions.asp write "sub doStuff" instead of sub doStuff()
Call the function as doStuff not doStuff()