Response and Request
To display any content to web browser, you can use "Response.Write".
The syntax is:
<%
Response.Write "This is my first ASP page."
%>
"Response.Write" is like all other ASP scripts, not case sensitive.
"Response.Write" is the same as "response.write". There
is another method to do the same work using "<%=" and "%>":
<%="This is my first ASP page."%>
The output is the same:
This is my first ASP page.
Please notice that, to display a string, we must use double quotes.
To understand Request, let's create two ASP pages:
first.asp:
<html>
<body>
<a href="second.asp?user=John">Send Query String</a>
<form action="second.asp" method="post">
<input type="text" name="user">
<input type="submit" value="Send Query String">
</form>
</body>
</html>
second.asp:
<html>
<body>
Hi <%response.write request("user")%>
</body>
</html>
Save the two pages in the same folder and open first.asp on web browser. Click
the link "Send Query String", you will see second.asp come out and
show the value "John":
Hi John
Back to first.asp. If you enter a value "Mike" in the text box, and
click the button "Send Query String", you will see the value "Mike"
displayed in second.asp:
Hi Mike
To retrieve the query string, we use Request. The syntax is:
request("<query string name>")
For example:
request("user")
To display this to a web page, we must use "Response.write" or "<%=%>":
<%response.write request("user")%>
<%=request("user")%>
To send a query string out, we should notice three points:
- Where do you want the query string sent to;
- What is the name of the query string;
- What is the value of the query string.
You can use a link or a form to send a query string out. In the above sample,
we point the query string to a destination page "second.asp", give
the query string a name "user" and a value "John".
<a href="second.asp?user=John">Send Query String</a>
Please notice that the express "second.asp?user=John" means: send
query string named "user" and it's value "John" to the page
named "second.asp". This work can be done by a form:
<form action="second.asp" method="post"> --------- destination
<input type="text" name="user"> --------- name and value
<input type="submit" value="Send Query String">
</form>
There is an advantage for using form to send query string that you can enter
any value into the text box without change the code in the page.
As you see, ASP can do something that can not be done by HTML. With HTML, you
can not sent data from one page to another page, but ASP can do this work.
|