Important alert: (current site time 7/15/2013 10:00:28 PM EDT)
 

article

Beginners guide to ASP filled with examples!

Email
Submitted on: 3/9/2002 8:22:40 PM
By: snowboardr 
Level: Beginner
User Rating: By 19 Users
Compatibility: ASP (Active Server Pages)
Views: 39785
(About the author)
 
     This is example for anyone who is just starting ASP. These are easy examples to understand. A live example of this can be found here: http://www.irideforlife.com/go?x=view If you like it the please vote!

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

Jason's Tutorial..



ASP - Active Server Pages
Outputing text

<%

Response.write "Hello World"

%>

Hello World

 

Outputing text a second way

<%

Response.write ("Hello World")

%>

Hello World

 

<html> & ASP

<%

Response.write ("<b>Hello World<b>")

%>

Hello World

 

Writing Date / Time

<%

Response.write NOW

%>

3/9/2002 8:15:19 PM

 

Comenting your code:

<%

Response.write "Hello World" 'Outputes "Hello world"

Note: A comment has a single quote in front of it. (')

%>

Hello World

 

If Statement

<%

If "2" = "2" Then

Response.write"True"

End if

%>

True

 

If ...Else

<%

If "2" = "3" Then

Response.write "True"

Else

Response.write "Its 2!"

End if

%>

Its 2!

 

Request.QueryString

<%

'If our QueryString matches what we want then we can show what we want

If Request.QueryString("display") = "message" then

Response.write "My message"

End if

 

%>

My message

 

More then 1 Request.QueryString

<%

'If our QueryString matches what we want then we can show what we want

If Request.QueryString("display") = "test" then

Response.write "QueryString "test" worked!"

End if

If Request.QueryString("show") = "test" then

Response.write "QueryString "test2" worked!"

End if

Note:

' Your linke will look something like this when clicked:

' default.asp?display=test&show="test"

' & Seperates QueryStrings in a link.

 

%>

QueryString test worked!QueryString test2 worked!

 

Include file

<%

<!--#include file="myfile.asp"-->

%>

Includes a file into your page. This makes it easy to have a bunch of code that you use all the time on one page, but yet you don't have to have a big long page of it. You can also just update the file with all your code, and then each page that has the include will have the update as well.

 

Write a form in ASP.

<%

Response.write "<form name=""form1"" method=""post"" action=""default.asp"">"
Response.write "<input type=""text"" name=""textfield"">"
Response.write "<input type=""submit"" name=""Submit"" value=""Submit"">"
Response.write "</form>"

'Note: Each quote inside the Response.write quotes must have double quotes!

'Example: Response.write "Hello there ""Welcome"" to my site!"

%>

Live Examples Here : http://www.irideforlife.com/go?x=view

 

Show your form results on the same page..

<%

Response.write "<form name=""form2"" method=""post"" action=""default.asp?display=formresults"">""
Response.write "<input type="text"" name=""areform"">"
Response.write "<input type=""submit"" name=""Submit"" value=""Submit"">"
Response.write "</form>"

If Request.QueryString("display") = "formresults" then

Response.write(Request.Form("areform"))

End if

%>

Live Examples Here : http://www.irideforlife.com/go?x=view

 

Dim to memory

<%

' Use this to store anything you want for use later also known as a string

MyText = "Hello World!"

Response.write(MyText)

%>

Hello World!

 

Replace something in a string

<%

MyString = "Jason is the best programmer in the world!"

NewString = Replace(MyString, "best","<b>worst</b>")

'Notes: YourNewString = Replace(String to look in, "Word that you want to look for", "Repalce with this" )

Response.write(NewString)

%>

Jason is the worst programmer in the world!

 

Select Combo

 

'This shows how to have the right one in the combo selected, depending on which they slected so even if the refresh it will stay on the right combo.

<form name="form1">

<select name="jumpmenu" onChange="MM_jumpMenu('parent',this,0)">
<option value="default.asp?link=test1" <% If Request.QueryString("link") = "test1" then Response.write "selected" %>>test1</option>
<option value="default.asp?link=test2"<% If Request.QueryString("link") = "test2" then Response.write "selected" %>>test2</option>
<option value="default.asp?link=test3" <% If Request.QueryString("link") = "test3" then Response.write "selected" %>>test3</option>
</select>
</form>

 

 

Math:

<%

a = "1"

b = "2"

c = a * b ' Multiplication

Response.write(c)

Response.write "<br>"

a = "1"

b = "2"

If a < b Then

Response.write "yes b is greater then a"

End if

%>

 

2
yes b is greater then a

 

Aray:

<%

MyArayString = "a b c | d | e f | g h i j | k l m n | o p | q r s | t u v | w y x z"

sAray = Split(MyArayString, "|") 'Split up our data in between | |

For each x in sAray

Response.write x

Next 'Goto next one until it there are no more

%>


a b c d e f g h i j k l m n o p q r s t u v w y x z

 

Leave comments below.

Ill probably continue on ths lesson if someone wants me to.

 

 

 


Other 21 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/9/2002 8:32:43 PMArt

I have some gaps in my asp knowledge and you just plugged one. Thanks and Keep up the good work!
(If this comment was disrespectful, please report it.)

 
3/9/2002 9:22:04 PMsnowboardr

Im glad it helped =D im writing another tutorial now cause I have nothing else to do. ;)
(If this comment was disrespectful, please report it.)

 
3/11/2002 7:19:18 PMsnowboardr

TUTORIAL 2

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7324&lngWId=4
(If this comment was disrespectful, please report it.)

 
3/15/2002 4:07:07 PMSue

This is a great tutorial. It is a good thing to have around when you quick reference.
(If this comment was disrespectful, please report it.)

 
4/12/2002 1:20:23 AMsqlguru2k

Loved these tutorials. Took me some time to find a simple but effective tutorial.

Excellent use of color coding etc.
(If this comment was disrespectful, please report it.)

 
4/12/2002 1:49:47 AMsqlguru2k

The following comment may sound a bit advanced for a target audience of beginners:

is & (ampersand) a "concatenation operator" or a "delimiter"?

I guess it could be both, depends on the perspective. The parser will see it as a delimiter...
(If this comment was disrespectful, please report it.)

 
5/31/2002 11:14:11 AMFrancois bujold

Good thanks
Ok now
1-how do I pass variables from one page to another (asp)
2 How do you compare bolean values from a databases? ie;
<% if rs2(9)= True then%>
or
<% if rs2.Fields(9).Value = True then %>

both statements are valid but do not catch or understand the bolean value
(If this comment was disrespectful, please report it.)

 
7/20/2002 7:49:57 AMDinesh

It's really a good site which help me a lot.
(If this comment was disrespectful, please report it.)

 
8/19/2002 2:34:25 PMmatt

wonderful, someone who can explain script clearly with related examples
(If this comment was disrespectful, please report it.)

 
9/4/2003 4:13:47 AM

I now feel confident in the basics, I created a page with some of the code above, saved it as a .asp in my site, and then set a link to it. When I click the link, nothing happens! I know that I am missing something - e.g. I have to add HTML formatting or something? Where is the missing link? Thanks for the really straightforward examples.
(If this comment was disrespectful, please report it.)

 
1/31/2005 3:36:16 AM

That's fine work for begineer Please keep it up!
(If this comment was disrespectful, please report it.)

 
2/26/2005 2:32:16 AM

hai this codes and way of presentation is good
(If this comment was disrespectful, please report it.)

 
1/3/2007 2:16:04 AM

Excellent

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.