Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

ASP - Order of code Standard

I am trying to find what is the best or most used to organize code in an ASP page, is there a standard ?

I have the following elements:

1) include files (<!--#include file="../Connections/CMS2003.asp" -->)

2) Recordsets

3) Additional scripts like:

<script language="JavaScript" type="text/JavaScript">
<!--
function ......
//-->
</script>

4) Links to other files like .css files

<link href="../SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css">
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>

5) HTML / ASP code displayed on the page

6) header tag
7) body tag

etc. ...

I am cleaning up a whole system and want to use the same ordering for all pages while I am at it.

What else should I consider when cleaning up an ASP page, like using include files for repeated code around the system, etc ?
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Can all includes go at the top of the page ?
Why are scripts and styles in the head tag and cant be before the recordsets say below the includes ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Thanks. Last thing ... i noticed you used:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

Some of my pages have that header, but some have:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>

What is the difference ?  should I change them to 65001 ?
The actual difference is javascript vs vbscript.  Classic asp can run either.  Also you can run vbscript even when the page is set for javascript and vice versa.  When running javasript like this it is really jscript and running server side.  If you are primarily using javascript, then keep it. If you are primarily using vbscript, then use that version.  

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>

In this case, don't confuse running javascript that is inside the asp tags <% %> with javascript such as spry.  Inside the asp tags, it is running on the server and not the client.  You can have both.  If you are manipulating your database, then it should be serverside.  If you are manipulating html or heavy math calculations, then run it client side.
Avatar of Aleks

ASKER

Yes, i just noticed one is for VBScript and one for Javascript.
Some pages are VB some are Javascript ... i will try and make as many as I can VBScript when possible to keep the system ASP/VB in its majority.

Thanks for your help !!!! I really apreciate it.
The organization that I showed you above is what the standards say you're supposed to do.  Browsers always try to make your code work but the further you get from the standards, the more trouble you can have.  If you rearrange things too much or out of order, then they won't work.  Includes for ASP code can go anywhere that makes sense but code that includes HTML must be in the correct place in the page.  You can't put HTML at the top or bottom of the page outside the <body> tag and expect it to work.