Using the RESPONSE Object
So what is this response object for? Response object is used to send output to the user from the server. There are many methods assigned to it.
Some of them that are used mostly are :
1. Response.Write "string"
If you're an ASP programmer, I believe you are very familiar with this one. If you're not then you will be, as soon as you start learning ASP.
The first thing you learn in every programming language is to display some text on screen (on this context, browser), isn't it? You use this method to do it.
Example:
<% response.write "Hello World" %>
will produce a "Hello World" output on your browser.
You can also combine some string and predefined variable using "&"
Example:
<%
Dim myVar
myVar = "Linawaty"
response.write "Hello.. My name is " & myVar & " (^-^)/"
%>
will produce a "Hello.. My name is Linawaty (^-^)/" output on your browser.
If you want to display some text or variable in the middle of lines of HTML, you can use shortcut <%="string"%>
It is practically the same as <% response.write "string" %>, just a little bit shorter and it doesn't allow anymore coding.
Example:
<% name = "Linawaty" %>
Assume you have predefined variable called "name" and you want to display it on the input box.
<form name="form" method="post" action="mypage.asp">
<input type="text" name="fullname" value="<%=name%>">
</form>
will produce an input box with "Linawaty" in it.
2. Response.Redirect "url"
This is another method of RESPONSE that you would find useful soon. We use this method to redirect to another page. It is the same as javascript's window.location="url"
Example:
We will create an ASP page that has a form with two buttons (say [page 2] and [page 3] buttons). Depends on which button you click, the script will redirect you to predefined page ([page 2] button to page2.html page and [page 3] button to page3.html page).
First we create a form with two buttons at "page1.asp"
page1.asp :
<%
if request.form("button")="page2" then
response.redirect "page2.html"
elseif request.form("button")="page3" then
response.redirect "page3.html"
end if
%>
<form name="form" method="post" action="page1.asp">
<input type="submit" name="button" value="page2">
<input type="submit" name="button" value="page3">
</form>
Then we create page2.html and page3.html so that each contains only some text to let you identify them.
Page2.html :
<html>
<head>
<title>Page 2</title>
</head>
<body>
This is Page 2.
</body>
</html>
Page3.html :
<html>
<head>
<title>Page 3</title>
</head>
<body>
This is Page 3.
</body>
</html>
3. Response.End
This method is used mainly for debugging. It will stop the ASP script at the exact point where it is inserted.
Example:
<%
response.write "First line"
response.end
response.write ", Second line"
%>
will produce a "First line" output on your browser instead of "First Line, Second Line".
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map
Content copyright © 2023 by Linawaty. All rights reserved.
This content was written by Linawaty. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.