How to use Response.Buffer and Flush - asp-classic

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"

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.

Stuck with classic ASP form submission

I am new to classic asp. I have developed a simple asp form where I am doing a form submission to access database. I got a code to do a form validation on fields but the code works only when I you same asp code. When I change the form method to different asp file, validation doesn't work.
Form.asp
....code
<%
Dim send, txtengineer, txtcaseid, txtassetno, txtusername, txtgroup, txtLOB, txtmodel, txtsim, countError
send = Request.Form("submit")
txtengineer = Request.Form("engineer")
txtcaseid = Request.Form("caseid")
txtasset = Request.Form("asset")
txtusername = Request.Form("username")
txtgroup = Request.Form("group")
txtLOB = Request.Form("lob")
txtmodel = Request.Form("model")
txtsim = Request.Form("sim")
countError = 0
%>
<form method="post" action="form.asp">
....
<%
if send <> "" AND txtcaseid = "" then
Response.Write "<span class=""message""> << Enter Case no.</span>"
countError = countError + 1
end If
%>
DB.asp
This is the code where I want to submit the collected field value. Which is working fine. I have forced to keep wherein I am want to do
I want to validate first then submit the form afterwards. I know I am doing something stupid.
Need some guidance to fix the code blocks.
Thanks.
The problem with having the form submit to a different page is, what do you do if there are errors? Tell the user to hit their "back" button? For that reason alone, I'd recommend putting the DB code in the same page as the form. If you can't do that, you need to move your server-side validation to the DB page. The client-side validation would still be on the form page. (Note that if you're only going to do one type of validation, it must be server-side.)
If you do everything in one page, the basic structure would look like this:
<html><head>[etc.]
<%
Const errstr = "<span class='err'>*</span>"
Dim txtengineer, txtcaseid '[etc.]
Dim counterror(8) '- 8 = number of fields
counterror(0) = 0
If Request.Form <> "" Then
txtengineer = Request.Form("engineer")
'etc. with other fields
Validate
If counterror(0) = 0 Then
SavetoDB
Response.Redirect "Success.asp"
End If
End If
Sub Validate()
If txtengineer = "" Then
counterror(1) = 1
counterror(0) = counterror(0) + 1
Else
'do whatever other cleanup/validation you need
End If
'etc. for other fields
End Sub
Sub SavetoDB()
'code to write stuff to database goes here
End Sub
%>
<script>
function validate(){
//client-side validation goes here
}
</script>
</head>
<body>
<%
If counterror(0) > 0 Then
Response.Write "<p>Please fill out the required fields (*) below.</p>"
End If
%>
<form method="post" action="form.asp">
<p>Engineer: <input type="text" name="engineer" value="<%=txtengineer%>" size="30" maxlength="50">
<%If counterror(1) = 1 Then Response.Write errstr%>
</p>
[etc. with other fields]
<p><input type="submit" name="Btn" value="Submit" onclick="validate();"></p>
</form>
</body>
</html>

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 .

Using a page variable as an if statements conditon within a control

I have the following problem:
I have the variable $GiftID on my page.
I want to cycle through all of my gift objects using my function getGifts().
When the $ID of the gift is equal to the $GiftID of the page then I want something to happen.
Here is an example of my code:
$GiftID
<% control getGifts %>
<% if CurrentPage.GiftID = ID %>This is it!<% end_if %>
<% end_control %>
Using $CurrentPage.GiftID works when printing inside the control, but how on earth do I access it from within the if statement?
I am using SS 2.9
I have not used ss2.9 yet, but as far as I know you can not do <% if Top.GiftID = ID %> in any 2.x version, you can not compare 2 variables, you can only compare with static vaules. (but it is possible in 3.0)
So you have to do it on php side, if you want to only display the slected gift object, then:
if GiftID is actually the DB field for the has_one relation of Gift then you can just do <% control Gift %> and it will scope the Gift object with the GiftID
If you really have GiftID saved as DB field or otherwise, then can do
public function getGift() { return DataObject::get_by_id('Gift', $this->GiftID); }
both ways you can do <% control Gift %> and it will scope it
If you want to list all gifts and mark the current gift then you need to do it on php side (foreach the set of objects and set a flag on the current object)
You should be able to access the current page with Top:
<% control getGifts %>
<% if Top.GiftID = ID %>This is it!<% end_if %>
<% end_control %>

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.

Resources