Search Tools Links Login

Beginners guide to ASP filled with examples!


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!

Original Author: snowboardr

Code



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.


  

  

 


  

 


 




About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 105 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.