ASP Programming Tips and Technique
[ Option Explicit ]
[ On Error resume Next ]
[ How to stop an ASP page Caching ]
- <% Option Explicit %>
- It is usually placed at the top of your asp page.
- Option Explicit requires that all variable names be declared (with the Dim statement). Using Option Explicit to force variable declaration is good for a number of reasons.
- Using Option Explicit forces you to declare all your variables before you use them. If you use a variable you haven't declared then an error will be generated and it will be easier for your debugging process.
[ On Error resume Next ]
- <% On Error resume Next%>
- It is usually placed at the top of your asp page.
- Easily trap and turn nasty error messages into easy on the eye messages that the user can understand.
- Example:
[ ASP Formatting Dates and Times ]<%
If Err.number <> 0 Then 'if there is an error
Response.Write ("Sorry you have encoutered an error." & "<br>")
Response.Write ("Your error number is " & Err.number & "<br>")
Response.Write ("The error source is " & Err.source & "<br>")
Response.Write ("The error description is " & Err.description & "<br>")
End If
%>
or you could redirect the user to a new page that contains all your custom made error message:
<%
If Err.number <> 0 Then 'if there is an error
Response.Redirect (my_error_message_page.asp) End If
%>
First, declare your variable as follow:
<%
Dim strNow
strNow = Now()
%>
and you can start manipulating the date and time..
- <%= Date() %> prints out 26/10/2007
- <%= Now() %> prints out 26/10/2007 08:13:51
- <%= Time() %> prints out 08:13:51
- <%= FormatDateTime(strNow, vbGeneralDate) %> prints out 26/10/2007
- <%= FormatDateTime(strNow, vbLongDate) %> prints out 26 October 2007
- <%= FormatDateTime(strNow,vbShortDate) %> prints out 26/10/2007
- <%= FormatDateTime(strNow, vbLongTime) %> prints out 08:13:51
- <%= FormatDateTime(strNow, vbShortTime) %> prints out 08:13
- <%= Year(strNow) %> prints out 2007
- <%= Month(strNow) %> prints out 10
- <%=Day(strNow) %> prints out 26
- <%=Hour(strNow) %> prints out 8
- <%=Minute(strNow) %> prints out 13
- <%=Second(strNow) %> prints out 51
- <%= WeekDay(strNow) %> prints out 6
- <%= WeekDayName(WeekDay(strNow)) %> prints out Friday
- <%= WeekDayName(WeekDay(strNow), 1) %> prints out Fri
[ How to stop an ASP page Caching ]
Everytime a page is loaded into the browser, that page will be loaded into the browser's cache. We don't want pages cached because if they are, credit card numbers, addresses and all kinds of stuff can be gathered from the cached page. How to stop an ASP page from being cached by the browser? Put this code on top of the pages that you want not to be cache by the browser.
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>
Now, your page is safe!
Total Comments 0
Comments
Recent Blog Entries by Monie
- ASP Programming Tips and Technique (Oct 26th, 2007)
- Usefull Programming Code (Oct 17th, 2007)



































