Quick Search for:  in language:    
ASP,will,teach,users,little,cool,tricks,Nothi
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 196,174. lines
 Jobs: 103. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Server Side PDF
By Igor Krupitsky on 11/20


Click here to see a screenshot of this code!Multiple Web Sites on one IP
By Richard J Mackey on 11/20

(Screen Shot)

Click here to see a screenshot of this code!Multiple websites on One IP
By Richard J Mackey on 11/20

(Screen Shot)

Click here to see a screenshot of this code!Combo-Box with Auto-Complete
By Mark Kahn on 11/18

(Screen Shot)

Click here to see a screenshot of this code!RegEx pattern match in VBScript
By moppy on 11/18

(Screen Shot)

Click here to see a screenshot of this code!Text-to-Speech in MS Outlook
By Nick Sumner on 11/18

(Screen Shot)

Click here to see a screenshot of this code!Rapid Classified Board v1.0 (beta)
By Gurgen Alaverdian on 11/17

(Screen Shot)

Adjust a GIF's Hue/Sat/Lum
By Mark Kahn on 11/17


Search Engine
By vsim on 11/17


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

A few cool ASP Tricks!

Print
Email
 

Submitted on: 10/15/2003 12:42:54 PM
By: Travis Howle  
Level: Intermediate
User Rating: By 12 Users
Compatibility:ASP (Active Server Pages), VbScript (browser/client side)

Users have accessed this article 3100 times.
 

(About the author)
 
     This will teach the users a little of the cool ASP tricks. Nothing to do with a database really, but They are still kinda cool just to test with!


 
 
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.
Forms are great for collecting and handling data on your website. But how can you use ASP to make the most of your forms? Most webhosts provide standard scripts for form handling, but to make your site truly dynamic, it will not be long before you want forms to do something more than the average generic script offers.

In this tutorial, we will look at how we can collect and begin to process data from submitted forms on your website. Let`s start with a basic form (say call the file form.asp) as below with two fields, name and email address:

< form method="post" action="formhandler.asp" < br>name="whateveryouwant">< br> Name: < input type="text" name="name">< br>
Email address: < input type="text" name="email">
< input type="submit" name="Submit" value="Submit">
< /form>

Now let`s begin to create formhandler.asp. The input from the form field called "name" is retrieved by calling request.form("name") and for the email form field, request.form("email"). Simple?

The first thing to consider is, what happens if someone leaves the fields blank. I imagine you don`t want to let them do that, so let`s set up a basic statement to handle that. We will be using If - Then - Else which is talked about in a later tutorial:

< %
If request.form("name")="" or request.form
("email")="" then
response.redirect "form.asp"
response.end
End if
% >

OK, so if either the name or email field were left blank, nothing is processed and the user is redirected back to the form to try again. In a later tutorial we may show you a nice way to highlight the fields that are required.

Right lets assume the user had the wit to actually input their name and email address. So what can you do with it? There are various possibilities: you could store the information in a database (more later on that), you could email it to yourself (again more later on this) or you could simply output the data on the webpage....ok that`s not very useful, but for the purposes of this basic tutorial it is what we will do.

So if you want to test this, set up your form.asp using the form code in the first codebox and set up formhandler.asp as follows:

< %
If request.form("name")="" or request.form
("email")="" then
response.redirect "form.asp"
response.end
End if

response.write "Name: " & request.form("name")
& "
Email: " & request.form("email")
response.end
% >

So simply, if both fields are filled in, it will output the Name and Email address. Note how you can combine text and ASP variables in your response.write statement as above.

----------------------------------------------------------

There are several different ways of displaying dates.
You can also add and subtract from them as well. I used one (1) in the examples below but, you can use any number you like.

Date 10/15/2003
< %=Date%>

Long Date Wednesday, October 15, 2003
< %=FormatDateTime(Now(),vbLongDate)%>

Adding to Long Date Thursday, October 16, 2003
< %=FormatDateTime(Now()+1,vbLongDate)%>

Subtracting From Long Date Tuesday, October 14, 2003
< %=FormatDateTime(Now()-1,vbLongDate)%>

Short Date 10/15/2003
< %=FormatDateTime(Now(),vbShortDate)%>

Adding To Short Date 10/16/2003
< %=FormatDateTime(Now()+1,vbShortDate)%>

Subtracting From Short Date Tuesday, October 14, 2003
< %=FormatDateTime(Now()-1,vbShortDate)%>

General Date 10/15/2003 4:32:27 PM
< %=FormatDateTime(Now(),vbGeneralDate)%>

Adding To General Date 10/16/2003 4:32:27 PM < %=FormatDateTime(Now()+1,vbGeneralDate)%>

Subtracting From General Date 10/14/2003 4:32:27 PM
< %=FormatDateTime(Now()-1,vbGeneralDate)%>

-----------------------------------------------------

To see if a specific file exists on the web server, then show the results to the user use the following code in an ASP page:

< %
Set fs=Server.CreateObject
("Scripting.FileSystemObject")

If (fs.FileExists("c:\inetpub\www\default.asp"))=true Then
Response.Write("File
c:\winnt\cursors\The DEFUALT.asp File exists.") Else
Response.Write("File c:\winnt\cursors\The File does not exist.")
End If

set fs=nothing
% >

-----------------------------------------------------

To check to see if a drive is ready. Such as drive D for a CD copy or something type:

< %
dim fs,d,n
set fs=Server.CreateObject
("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
n = "The " & d.DriveLetter
if d.IsReady=true then
n = n & " drive is ready."
else
n = n & " drive is not ready."
end if
Response.Write(n)
set d=nothing
set fs=nothing
% >


I hope you liked it! And I hope it helped you :D Pleaes remember to vote! lol ;)

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Intermediate 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
10/15/2003 12:50:41 PM:Travis Howle
I hope you like it :$
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/16/2003 9:42:16 AM:
I'm sorry, but these aren't tricks. These are basic things that anybody can find in a 'Learn asp" type book. It isn't intermidiate either.. try beginner. You don't ever cover server.mapppath since most users don't know the full path to their website on the webserver. Finally, you say this is client side compatible, which it isn't. Client-side vbscript doesn't understand 'Server.CreateObject'
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/16/2003 12:50:44 PM:Brian Battles WS1O
Sorry, but these are NOT "cool ASP tricks," they're just very simple techniques that all ASP programmers should learn right at the start. Definitely beginning-level stuff, not especially fresh or unique. Nice of you to make the effort, but this material is easily found in many other places. Also, be careful of your spelling (eg, "DEFUALT," "plaes," etc. It makes you look amateurish.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/16/2003 5:37:26 PM:Travis Howle
Sorry then. Ill try ot make something better that will get a better score of votes.. Wait.. Lets ask you. What do you think I should post, What do you want ot know?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/16/2003 5:53:31 PM:
Travis, thanks, I found a couple things in your article to add to my repertoire. Thanks for taking the time to give back to the asp community!!! (BTW, to Travis' critics: I have a couple of very popular and "important" websites and I've been asp coding for a couple of years now. Sometimes, finding tips on the "basic" things are the toughest because everyone assumes that everyone else already knows all that.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/17/2003 10:13:01 AM:
(I had my name on that last one, not sure why it didn't show up - Brian) I'm fine with people posting the basics and I agree that they can be useful. But if that's what they are posting then that is what it should be called, not intermidiate 'tricks'. Here's one I've been looking for.. how about authenticating someone against a domain controller from a custom login screen.. NOT using IIS's login pop-up AND getting the proper credentials so that the user then has rights to the appropriate files on the server based on their login information.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/20/2003 8:42:09 AM:Brian Battles WS1O
Travis, some handy stuff for beginners might include showing them how to send e-mail with CDONTS or CDOSYS, how to send Server.QueryString data from one page to another, showing how to use form fields, the difference between POST and GET, etc. Just a few suggestions...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/20/2003 7:00:03 AM:mackeyrj
I agree with the crowd. The info is not at the intermidiate level, but the info is very useful for beginners. Don't feel too discouraged to continue making submissions. Just be be critical of the level they are submitted to.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/20/2003 9:33:47 AM:
All stop! This tutorial is good and sholud be a very good remainder to all asp programmers of simplicity and good programming skills. So don´t be nasty...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/20/2003 9:39:32 AM:
Silly!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.