Forum Moderators: open

Message Too Old, No Replies

A Beginner's Guide To ASP

Part 1 of 3 :: response and request

         

cmatcme

8:29 am on Apr 3, 2005 (gmt 0)

10+ Year Member



Hi everybody. Over the next couple of days, I'm going to be posting a beginner's guide to asp, something I would've love to have had when I started.

Part 1 :: response and request ::

One of the very basic but by all means very useful elements are the response and request items. I'm going to explain three of each:

1. response.write - So simple but so useful, used to write text in an asp document:

 response.write "Blue Widgets" 

Displays Blue Widgets on the user's page. This command can be used to display html coding too. Other people prefer to use parantheses around the speech marks.

2. response.redirect - Used to immediately redirect a user from one page to another (unlike meta http-redirect which takes time):

 response.redirect "index.asp" 

Redirects the user to the start page which may also be default.asp. You can redirect users to another website just like you would with meta http-redirect.

3. response.cookies - When cookies are enabled in the user's browser it sets cookies in it. This command is commonly used to give more control over an individual user.

 response.cookies ("itsname") = "whatsinsidethecookie" 

This sets a cookie in the browser with a name itsname and a value whatsinsidethecookie. It will expire or be deleted when the browser closes

 response.cookies ("itsname") = "whatsinsidethecookie"
response.cookies ("itsname").Expires=#Jan 10,2007#

This cookie expires on January 10th 2007 in the time zone the user is in.

______________________

4. request.form - This is used to request information that a user sent of in a form.

Say the user was told to enter their email address in a form and they gave e@xample.com and the name of the box they entered it in in was email. Then in order to display it on another page, we'd have to use response.write (told you it was useful ;) )

 response.write request.form ("email")

would display the email address he entered be it whatever.

5. request.querystring - This is used to request information set in a querystring.

Much the same as request.form. More info see here [devpapers.com]

6. request.cookies - This is used to request cookies that you may previously set.

Earlier on we set our cookies with the name itsname so as long as it's before January 10 2007 this would work.

 response.write request.cookies("itsname") 

By doing this you display what's inside it and so it would display whatsinsidethecookie.

7. request - Just by itself

This is the same as all above but requests information in priority order. It will check to see if it can request any information from a form, then a querystring and finally a cookie. If your trying to request information from a low priority be specific!

Remember:

1. Put all asp commands inside <% %>
2. All pages where commands are featured have to have a .asp extension

cmatcme

topr8

8:59 am on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks a nice intro!

what confused me a little when i started was the way the same thing could be written in two ways eg.

response.write "Hello"

response.write("Hello")