QUICK REFERENCE

Home

Section 01
Lesson 01
Lesson 02
Lesson 03
Lesson 04
Lesson 05

Section 02
Lesson 06
Lesson 07
Lesson 08
Lesson 09

Section 03
Lesson 10
Lesson 11
Lesson 12
Lesson 13

Section 04
Lesson 14
Lesson 15

Section 05
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20

The Response Methods

The Response Object:

Response is one of six (6) ASP Objects. It represents the server's response to a web browser. Response has eight (8) methods, nine (9) properties, and one (1) collection. In this lesson we will focus on the methods.

Methods:

Response Methods
AddHeader( )Response.AddHeader("myHeader","My Value")
Add your own HTML Header(s)
AppendToLog( )Response.AppendToLog("My log message")
Send a message to the server log
BinaryWrite( )Response.BinaryWrite(binaryData)
Writes binary data such as pictures etc.
Clear( )Response.Clear()
Clears buffered response if Response.Buffer = true
End( )Response.End()
Ends the response
Flush( )Response.Flush()
Sends buffered response if Response.Buffer = true
Redirect( )Response.Redirect("http://somewhere.com/page.html")
Redirects browser to different page
Write( )Response.Write(variables + " and text")
Outputs response to the browser

In JavaScript, the ASP Methods utilize parenthesis. Please notice that two of the methods depend upon Response.Buffer, which we will cover in the next lesson. Also, notice that if you use AddHeader() or Redirect(), then they must execute prior to Write().

Each method is demonstrated and described above. I will not go over each method redundantly. I will, however, spend a little extra time with the two methods that you are likely to use the most.

Write() and Redirect():

Below are two ASP scripts for Lesson 06.

<%@LANGUAGE="JavaScript"%>
<%
//No ASP Here, just a regular HTML Page
%>
<HTML>
<FORM ACTION="script06a.asp" METHOD="Post">
<STRONG>Do you want to be redirected to Google.com?</STRONG><BR>
<SELECT NAME="redirectionVariable">
<OPTION>Yes, I do.</OPTION>
<OPTION>No, I do not.</OPTION>
<OPTION>Who is Google?</OPTION>
</SELECT><BR>
<INPUT TYPE="Submit" VALUE="Submit">
</FORM>
</HTML>

Click Here to run the script in a new window. Below is script06a.asp; the one that does all the heavy lifting.

<%@LANGUAGE="JavaScript"%>
<%
var redirectionVariable = new String( Request.Form("redirectionVariable") )

if (redirectionVariable == "Who is Google?")
	{
	whoGoogle()
	}
if (redirectionVariable == "Yes, I do.")
	{
	Response.Redirect("http://www.google.com")
	}
if (redirectionVariable == "No, I do not.")
	{
	Response.Redirect("script06b.asp")
	}
if (redirectionVariable == "undefined")
	{
	Response.Redirect("script06.asp")
	}

function whoGoogle()
	{
	Response.Write("<HTML>\r")
	Response.Write("Google is a search Engine.<BR>\r")
	Response.Write("You should try it. It's pretty good.<BR>\r")
	Response.Write("</HTML>\r")
	}
%>

The script above demonstrates Write() and Redirect() pretty well. Response.Write() is very similar to document.write(). Just remember, Response is an ASP Object and Write() is an ASP method.

Notice that I can encapsulate Response.Write() statements inside a JavaScript function. I could have put that function in the script before Response.Redirect(). However, Response.Write() cannot be executed prior to Response.Redirect() or else there will be an error.

The Write( ) Shortcut:

The best way to deal with this subject is to dig right in. Check out the script below.

<%@LANGUAGE="JavaScript"%>
<HTML>
<HEAD>
<% var timeAndDate = new Date() %>
<TITLE><%=timeAndDate%></TITLE>
</HEAD>
<BODY>
The Time and Date are <%=timeAndDate%>.<BR><BR>
<%
var greeting = "Hello"
greeting += " World!"
%>
<%=greeting%>
</BODY>
</HTML>

Click Here to run the script in a new window.

Using the shortcut in the script above I can output either a JavaScript data type or an ASP native data type. In the above example I'm only outputting JavaScript values. I could also do something like the sample code below.

<HTML>
<%=Request.Form("someValue")%>
</HTML>

Notice the equal sign. Also notice that you can only "shortcut" one value at a time. Multiple variables, concatenations, etc. don't go inside the shortcut.

Also notice that everything in this script is executed in linear order. That wasn't true when created scripts with the RUNAT attribute.

Our next stop is Response Properties in lesson 07.

Next up.... lesson07.asp

Google
 
Web aspjavascript.com

Copyright James Clark 2005