Quick Search for:  in language:    
ASP,Good,information,help,building,page
   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



 
 
   

How to start a good page with ASP

Print
Email
 

Submitted on: 10/18/2003 5:08:59 AM
By: Bruno Martins Braga  
Level: Beginner
User Rating: Unrated
Compatibility:ASP (Active Server Pages), VbScript (browser/client side)

Users have accessed this article 1526 times.
 

(About the author)
 
     Good information to help building a good ASP page.

 
 
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.

@

First of all, we have to organize our page to easily find any part of the code we insered. It`s very important for you to put signs or usefull information in case you don`t remember what it was.

P.S.: This is a tutorial, so please read carefully all the information before using any code.

1) First step of the page

<%@Language = "VBScript"%>
<%
Option Explicit
response.expires = 0
response.expiresabsolute = Now() -1
response.addHeader "pragma","no-cache"
response.addHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>

I always use a code in ASP, which has a particular function:

- To force the browser to read the web page from the server, and not from the cache of the computer
For persons who are not pretty familiar with this, don`t worry, because s quite simple: everytime a page is loaded by a browser, depending on the configurations of couse, it will save some information about this site, specially if you see it with frequently. If that happens, the next time you try to see the page, it will be displayed the stored file from that address, not the real page from the server. As ASP pages are known because they are dinamical, we would lose this functionallity. This function just asks the browser to not keep any "cache" inside the computer. Later, you will see that this same code will help you to keep the "Logout" (particular page to make the log out inside a web page) more secured.

- To request that all variables to be Dimensioned.
It`s pretty usefull because it helps us to check if there is any variable we are using by mistake, or incorrectly. t`s not a necessary command, but I advise, to keep the programming sequence more organized.

Bu, it also has its problems:

- I said that it will refresh everytime from the server, not keeping any info inside the cache. The problem is that everytime, the page will load all images again, even if they are the same. For non fast internet connections, it might be a difference. But, anyway, if you want something very dinamic, I suggest to use it, or the visitor won`t be able to see your dinamic page...

@

2) Inserting the explanation

In ASP code, the symbol used to ignore a code line is " ' ". But you can use it in any place, being aware of the details:

- After you used this char, on the same line, any code won`t be seen as a code, but as text.
Eg:

<%
'This line is text

Dim var1     'This var is for counting
Dim var2     'This var is for catching
%>

@

3) Organizing the page functions - DIM

I prefer to guide all variables to the top of the page, even before the HTML tags. It helps you not using the same variable twice. In long programs, it may happen.

Another thing is to dimension a variable with a characteristic name that will help you to catch its meaning right away. Avoid using simple letters like "i" or "var". It will become a mess for long programming. Don`t be afraid of calling a variable as "TextFromFormToBeChanged". The computer will accept it and you will never forget the idea of its value. As you see, we usually try to put the first letter of a word in CAPS, to be easier to read it later.

@

4) Functions, Sequences & Misc.

Just a part to say how much interest it is when you organize your code in a way you can see the structure and recognise quickly what is going on. For example, let`s see the command For - Next.

<%
For i=1 to 10
response.write i
Next
%>

When you see this code, it`s not quite difficult to get its idea. It will print on screen the sequence of numbers from 1 to 10. And, if this code is inside some another code, you won`t mistake its function. But, this is a case we usually don`t use, you should know this by now. That`s why we try to separate dependent lines with the "TAB" button... This would turn to:

<%
For i=1 to 10
    response.write i
Next
%>

It does not seem to be changed a lot, but, with long programming, believe, it`s very important. 

I took one example I usually do in my websites, to check this idea...

This next code check if a variable has a value, then randomizes for a value that must be different from the first one. But don`t worry with its funcionallity, that`s not that intention right now.

<%
If request("CorDefinida") = "" then 
Randomize 
CorRandom = Int((TotalCores * Rnd()) + 1)
if CorRandom = Session("CorSite") then
While CorRandom = session("CorSite")
randomize 
CorRandom = Int((TotalCores * Rnd()) + 1)
Wend
end if
Session("CorSite") = Cores(CorRandom)
else
Session("CorSite") = request("CorDefinida")
end if
%>

But, look to the difference of reading this code, and the next one...

<%
If request("CorDefinida") = "" then 
    Randomize 
    CorRandom = Int((TotalCores * Rnd()) + 1)
    if CorRandom = Session("CorSite") then
        While CorRandom = session("CorSite")
            Randomize 
            CorRandom = Int((TotalCores * Rnd()) + 1)
        Wend
    end if
    Session("CorSite") = Cores(CorRandom)
else
    Session("CorSite") = request("CorDefinida")
end if
%>

What do you think? Makeing the code clear like this, you help yourself getting bugs, and even improving the code later.

Happy programming...


Other 3 submission(s) by this author

 

 
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 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
10/19/2003 11:18:48 PM:
hey...that's really nice. A good tips.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/20/2003 11:16:57 AM:
this is an excellent article an I've learned a lot from it. I thank you a lot. Your article helps me a lot.
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.