Tweet
One of the most often asked question in forums is "how do I pass an ASP variable to JavaScript?"
It is quite common to find out that people ask the question the other way round: "How do I pass a JavaScript variable to ASP?"
Ok, the two things are completely different and they involve completely different solutions.
First of all, let me explain something you might already know. ASP (or to be precise VBScript) is a server side language, while JavaScript is a client side language. The two work on different levels: ASP is executed before the page is completely loaded, while JavaScript works only after that. For that reason we cannot pass a JavaScript variable to ASP without reloading the page.
Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts
Tuesday, 16 April 2013
Tuesday, 19 March 2013
ASP: conditional statements with If...Then...Else...ElseIf
Tweet
In ASP we can use conditional statements in different ways. The basic syntax we are used to, is If ... Then ... Else ... End, however we will see that there are some interesting things about it.
First of all let's consider a simple conditional statement in ASP. As you already know, we do not use any brackets or parenthesis. A basic example could be:
In ASP we can use conditional statements in different ways. The basic syntax we are used to, is If ... Then ... Else ... End, however we will see that there are some interesting things about it.
First of all let's consider a simple conditional statement in ASP. As you already know, we do not use any brackets or parenthesis. A basic example could be:
<%
Dim numVar
numVar = 5
If numVar = 5 then
response.write("The variable numVar is 5")
End if
%>
Tuesday, 19 February 2013
ASP: CDate
Tweet
CDate is an ASP function that converts a valid date and time string to a Date Type value and returns it.
Because of the above we need to use another ASP function in order to be sure to convert a valid date. The function's IsDate.
In the following short post, we are going to see how to use both functions and create a short script that converts a date.
CDate is an ASP function that converts a valid date and time string to a Date Type value and returns it.
Because of the above we need to use another ASP function in order to be sure to convert a valid date. The function's IsDate.
In the following short post, we are going to see how to use both functions and create a short script that converts a date.
Tuesday, 5 February 2013
ASP: URL Rewrite and IIS7
Tweet
Following a kind suggestion by a follower, today we are going to see how to use IIS URL Rewrite 2.0 for IIS 7.
First of all, what's URL Rewrite?
Rest assured, we can use it for a classic ASP site as well.
What we need to do is:
1) install URL Rewrite after downloading it from the Ms IIS site;
2) enable ASP.NET role service on IIS 7;
3) write a rule
Following a kind suggestion by a follower, today we are going to see how to use IIS URL Rewrite 2.0 for IIS 7.
First of all, what's URL Rewrite?
"IIS URL Rewrite 2.0 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. By using rule templates, rewrite maps, .NET providers, and other functionality integrated into IIS Manager, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and even complex programmatic rules. In addition, Web administrators can perform redirects, send custom responses, or stop HTTP requests based on the logic expressed in the rewrite rules."
Rest assured, we can use it for a classic ASP site as well.
What we need to do is:
1) install URL Rewrite after downloading it from the Ms IIS site;
2) enable ASP.NET role service on IIS 7;
3) write a rule
Thursday, 17 January 2013
ASP: special characters
Tweet

One of things that newbies find difficult when trying to learn ASP is the way code is tructured and what all those special characters are there for.
In this short post we are going to see the most common special characters we can find in an ASP page:

One of things that newbies find difficult when trying to learn ASP is the way code is tructured and what all those special characters are there for.
In this short post we are going to see the most common special characters we can find in an ASP page:
- &
- '
- _
- :
- .
- <% ... %>
- <%= ... %>
Tuesday, 15 January 2013
ASP: variables naming convention
Tweet
When naming variables in ASP, we should consider some conventions.
Because the way we write code is quite important for us and, possibly, other people, we do need to keep things as much readable as we can. That means, for example, we should use indents when writing procedures and functions or we should follow a common structure in code blocks.
In general we need to make things easy to read and understand.
That is why there are common naming convention for variables. And in this article we are going to explore them.
When naming variables in ASP, we should consider some conventions.
Because the way we write code is quite important for us and, possibly, other people, we do need to keep things as much readable as we can. That means, for example, we should use indents when writing procedures and functions or we should follow a common structure in code blocks.
In general we need to make things easy to read and understand.
That is why there are common naming convention for variables. And in this article we are going to explore them.
Thursday, 13 December 2012
ASP: permanent redirect with HTTP 301 status code
Tweet
There are situations when we need to redirect the visitor to a web site to another place.
This is done for example when the web site is no longer updated or valid.
In order to do so we can redirect the visitor permanently with HTTP 301 response code. That is done because we need to tell the user-agent that the location is permanently moved elsewhere.
I believe you all know what HTTP headers are... or maybe we should start from there...
There are situations when we need to redirect the visitor to a web site to another place.
This is done for example when the web site is no longer updated or valid.
In order to do so we can redirect the visitor permanently with HTTP 301 response code. That is done because we need to tell the user-agent that the location is permanently moved elsewhere.
I believe you all know what HTTP headers are... or maybe we should start from there...
Tuesday, 23 October 2012
ASP: CursorType and LockType
Tweet
With ASP we usually connect and retrieve data from a database. We do it almost every day and we use the relative code without really thinking about it. Things are working and we get what we need, however... do we really know what we are doing?
I’m talking about two particular properties: CursorType and LockType.
In my experience, when I first used ASP to open a recordset, I used the two properties without really understanding their significance. But, because I am basically a curious guy, I wanted to understand what those numbers are, why I needed to use them and why I got different results, when changing them.
Let’s see together what are those two properties.
With ASP we usually connect and retrieve data from a database. We do it almost every day and we use the relative code without really thinking about it. Things are working and we get what we need, however... do we really know what we are doing?
I’m talking about two particular properties: CursorType and LockType.
In my experience, when I first used ASP to open a recordset, I used the two properties without really understanding their significance. But, because I am basically a curious guy, I wanted to understand what those numbers are, why I needed to use them and why I got different results, when changing them.
Let’s see together what are those two properties.
Tuesday, 2 October 2012
ASP: the InStr function
Tweet
One of the most used functions in ASP is InStr.
In this short article we are going to see how to use it.
startOfStr is optional and it specifies where the search will begin. By default is set to1 (first character of the string). It is required when compare is used.
One of the most used functions in ASP is InStr.
In this short article we are going to see how to use it.
The Syntax
The InStr function has the following syntax:
InStr([startOfStr,]stringSearched,search[,compare])
where:startOfStr is optional and it specifies where the search will begin. By default is set to1 (first character of the string). It is required when compare is used.
Thursday, 27 September 2012
ASP: how to get a file extension
Tweet
While we have already seen how to upload files and how to work with the Scripting.FileSystemObject, today we are going to see how to get a file extension, for example before authorising a user to upload a file to our server. We all know very well how important is security when working with the file system objects: for example, we don't want the user to upload executable, or other potentially malicious files on our server.
Said that, we can create a short ASP function to check the file extension, and grant or deny the upload.
Let's see how...
While we have already seen how to upload files and how to work with the Scripting.FileSystemObject, today we are going to see how to get a file extension, for example before authorising a user to upload a file to our server. We all know very well how important is security when working with the file system objects: for example, we don't want the user to upload executable, or other potentially malicious files on our server.
Said that, we can create a short ASP function to check the file extension, and grant or deny the upload.
Let's see how...
Tuesday, 25 September 2012
ASP: how to keep track of downloaded files
Tweet
Today we are going to see how we can keep track of downloaded files in a web site.
We normally link files with an hyperlink. The trick in this case is to pass the file information to another ASP page and then - after "taking note" of the relevant information - initiate the download.
Ready to see the code? Follow me...
Today we are going to see how we can keep track of downloaded files in a web site.
We normally link files with an hyperlink. The trick in this case is to pass the file information to another ASP page and then - after "taking note" of the relevant information - initiate the download.
Ready to see the code? Follow me...
Thursday, 13 September 2012
IIS: customised error messages
Tweet
Hey everybody! Today we are going to work on IIS, and give those boring error messages a new look.
Customising error pages is an underestimated thing by most web developer. However, as you may understand, it can really make our web site different, and - for example - prevent visitors from going away.
In order to customise the error pages we need to use IIS Manager on the web server. If you're not the server administrator, you can always ask for help. If your web site is hosted somewhere by some web hosting company, well... check if you've access to such configuration from your web site control panel (if you've such a tool) or ask the company directly.
Now... let's see how to customise error messages.
Hey everybody! Today we are going to work on IIS, and give those boring error messages a new look.
Customising error pages is an underestimated thing by most web developer. However, as you may understand, it can really make our web site different, and - for example - prevent visitors from going away.
In order to customise the error pages we need to use IIS Manager on the web server. If you're not the server administrator, you can always ask for help. If your web site is hosted somewhere by some web hosting company, well... check if you've access to such configuration from your web site control panel (if you've such a tool) or ask the company directly.
Now... let's see how to customise error messages.
Tuesday, 21 August 2012
ASP: database connection strings (basic)
Tweet
After a few days of deserved rest, here we get back to work! No that I want to, but I'm sure you are all waiting for new posts ... ... ... or not?
In the following short article I would like to list all possible database connection strings, just in case you need them in your projects. We will see just the basic way of connecting to data sources, so keep in mind that specific additional security parameters may be used, in case you need them.
Ready? Then please follow me...
After a few days of deserved rest, here we get back to work! No that I want to, but I'm sure you are all waiting for new posts ... ... ... or not?
In the following short article I would like to list all possible database connection strings, just in case you need them in your projects. We will see just the basic way of connecting to data sources, so keep in mind that specific additional security parameters may be used, in case you need them.
Ready? Then please follow me...
Thursday, 9 August 2012
ASP: not installed by default on IIS
Tweet
As almost all the web thought readers know, I am a long time ASP fan - and as I can see from your comments, many of you feel the same way.
With the most new (!) MS operating systems, when we install IIS, classic ASP is not included by default. We are talking about IIS7.0 and 7.5 here.
Accustomed to having ASP automatically installed, when we see a HTTP 404 error on our browser the first time we browse our beloved ASP web site, we remain completely lost. That happened to me in the past, because I couldn't imagine the real situation behind it.
Is MS trying to put ASP aside? I don't think so, but surely they are trying to promote .NET in any possible way.
Ok. If you don't know how to install classic ASP in IIS and your great .asp pages are not shining in all their glory, here you will find a quick and swift solution.
Follow me...
As almost all the web thought readers know, I am a long time ASP fan - and as I can see from your comments, many of you feel the same way.
With the most new (!) MS operating systems, when we install IIS, classic ASP is not included by default. We are talking about IIS7.0 and 7.5 here.
Accustomed to having ASP automatically installed, when we see a HTTP 404 error on our browser the first time we browse our beloved ASP web site, we remain completely lost. That happened to me in the past, because I couldn't imagine the real situation behind it.
Is MS trying to put ASP aside? I don't think so, but surely they are trying to promote .NET in any possible way.
Ok. If you don't know how to install classic ASP in IIS and your great .asp pages are not shining in all their glory, here you will find a quick and swift solution.
Follow me...
Thursday, 5 July 2012
ASP: how to use datediff
Tweet
As I said in my last post, today we are going to explore a VBScript function called DateDiff. There's not much mystery behind it, in fact, as the name says, DateDiff calculates the difference between two dates. The resulting value can be in different format and, generally speaking, the function can be used in many situations.
let's see how it works.
As I said in my last post, today we are going to explore a VBScript function called DateDiff. There's not much mystery behind it, in fact, as the name says, DateDiff calculates the difference between two dates. The resulting value can be in different format and, generally speaking, the function can be used in many situations.
let's see how it works.
Tuesday, 3 July 2012
ASP: how to use dateadd
Tweet
ASP is a powerful tool. Here, as usual, we are talking about a VBScript function that let us manipulate dates: DateAdd.
Whenever we need to perform operations on a date, we can benefit from the use of the this function. In the following post we are going to see how to use it.
ASP is a powerful tool. Here, as usual, we are talking about a VBScript function that let us manipulate dates: DateAdd.
Whenever we need to perform operations on a date, we can benefit from the use of the this function. In the following post we are going to see how to use it.
Tuesday, 26 June 2012
CSS & ASP: let the user choose the style
Tweet
When we create a web site, we usually decide the look of it and the way the visitor is actually experiencing it. Sometimes we might need to create different look for the same site, especially if we are dealing with specific groups of users. I'm going to explain in a simple way how to let the user choose the style of the web page according to its needs. To do so, we are going to use CSS and ASP.
When we create a web site, we usually decide the look of it and the way the visitor is actually experiencing it. Sometimes we might need to create different look for the same site, especially if we are dealing with specific groups of users. I'm going to explain in a simple way how to let the user choose the style of the web page according to its needs. To do so, we are going to use CSS and ASP.
Monday, 21 May 2012
ASP & jQuery: linked list boxes with AJAX
Tweet
Today, I would like to share a quick and easy solution to link 2 list boxes with jQuery and AJAX.
Situation: we have two list boxes. One (number) is already populated. The second (letter) is populated according to what is selected on the first list box, via AJAX (not reloading the page).
We need to build two ASP pages.
Let's start and have fun!
Today, I would like to share a quick and easy solution to link 2 list boxes with jQuery and AJAX.
Situation: we have two list boxes. One (number) is already populated. The second (letter) is populated according to what is selected on the first list box, via AJAX (not reloading the page).
We need to build two ASP pages.
Let's start and have fun!
Friday, 4 May 2012
ASP: avoid SQL injections
Tweet
If you work a lot with ASP and SQL, you might already know about SQL injections.
It's quite clear that every time we offer a visitor the possibility of filling a form (whatever its purpose may be), there's a security risk for our database. Basically, an attacker can insert some code in a form element, which will serve as a breach, allowing access to data stored in the database.
How that's done is not the main topic of this short post, however we should be aware of the fact that those threats are often used to update, delete and insert data, or in worst cases, they are used in order to gain access to reserved areas of a web site.
In this article, we are going to create a small VBScript function to avoid SQL injections.
If you work a lot with ASP and SQL, you might already know about SQL injections.
It's quite clear that every time we offer a visitor the possibility of filling a form (whatever its purpose may be), there's a security risk for our database. Basically, an attacker can insert some code in a form element, which will serve as a breach, allowing access to data stored in the database.
How that's done is not the main topic of this short post, however we should be aware of the fact that those threats are often used to update, delete and insert data, or in worst cases, they are used in order to gain access to reserved areas of a web site.
In this article, we are going to create a small VBScript function to avoid SQL injections.
Monday, 23 April 2012
VBScript: how to schedule the opening of an ASP page
Tweet
Following an exchange of ideas with Still_ASP, a loyal reader of the web thought, I thought to write something about scheduling events on a Windows server.
Sometimes we might need to trigger some events independently from the actual opening of a page or a specific action taken by a user. If nobody is browsing your page, how could we trigger an event anyway?
To do so, we need to use a little trick that I will shortly explain.
Following an exchange of ideas with Still_ASP, a loyal reader of the web thought, I thought to write something about scheduling events on a Windows server.
Sometimes we might need to trigger some events independently from the actual opening of a page or a specific action taken by a user. If nobody is browsing your page, how could we trigger an event anyway?
To do so, we need to use a little trick that I will shortly explain.
Subscribe to:
Posts (Atom)
