Convert asp classic to asp .net easily with just a few changes

The way to code, develop and build a website, intranet or application between asp classic and asp .net are different. In my opinion, those differences is a lot.
Even though, they are possess similar programming language like visual basic but the mind set to develop, in common ways, both are not same. Developer who used to use asp classic learn asp .net will find a new things.

However, in this post, I give example on how to convert asp classic to asp .net so that it can be run on web hosting which supports .net. Convertion will use ‘asp classic’ like code. It does not use any software tools.
Asp classic developers can use their experties to build .aspx website. Again they also need to learn asp .net controls and recommended methods from Microsoft to build an application because it increases productivity.

Let’s assume we have database table ‘tb_customers’ with just two columns which are customer and city. The .aspx files that has asp classic code like will operate with that table using ADODB objects

Summary of the things to note are as below:

  1. Add page directive on top of script.
  2. Every variables must be declared with ‘dim’.
  3. ‘Let’ and ‘Set’ assignment statements are no longer supported. Do not use ‘Set’ assignment in your script anymore.
  4. Every functions and procedures must have open/close parantheses on its arguments / parameters i.e response.write(“hello”) instead of response.write “hello”
  5. When getting recordset field value, it must use complete syntax (with ‘.value’) i.e rs(“fieldname”).value

Only few things we need to consider and here is the example of .aspx file:

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adUseClient = 3

dim conn
conn = Server.CreateObject("ADODB.Connection") ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath(".") & "\dbtest.mdb")
dim rs
rs = Server.CreateObject("ADODB.Recordset")
rs.PageSize = 10
rs.CursorLocation = adUseClient ("Select * from tb_customer", conn, adOpenForwardOnly, adLockReadOnly)

If Len(Request.QueryString("page")) = 0 Then
   rs.AbsolutePage = 1
   If CInt(Request.QueryString("page")) <= rs.PageCount Then
     rs.AbsolutePage = Request.QueryString("page")
     rs.AbsolutePage = 1
   End If
End If

Dim abspage, pagecnt
abspage = rs.AbsolutePage
pagecnt = rs.PageCount

response.write ("<table id='thetable' border=1 width='50%'>")
response.write ("<thead><tr>")

dim i, j, f

for each f in rs.Fields
   response.write ("<th>" & f.Name & "</th>")
response.write ("</tr></thead>")
if not rs.EOF then

   response.write ("<tbody>")

   for i = 1 to rs.PageSize
     if rs.EOf then exit for

     response.write ("<tr><td>" & rs(0).value & "</td>")
   for j = 1 to rs.Fields.Count -1
     response.write ("<td>")
     if not isdbnull(rs(j).value) then
       response.write (rs(j).value)
       response.write ("-")
     end if
    response.write ("</td>")

   response.write ("</tr>")


   response.write ("</tbody>")
end if
response.write ("<tfoot>")
response.write ("<tr><td colspan=" & (rs.fields.count) & ">")
if pagecnt > 1 then
   for i = 1 to pagecnt
     response.write ("<a href='default.aspx?page=" & i & "'>" & i & "</a>  ")
end if
response.write ("</td></tr>")
response.write ("</tfoot>")
response.write ("</table>")


Save as default.aspx then run it

Agung Gugiaji

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s