Component-based Classic ASP — React in Classic ASP??? 😮

Component-based Classic ASP — React in Classic ASP??? 😮
Photo by Goh Rhy Yan on Unsplash

Lately I have been working a lot with React and Redux, and have found the concept of creating reusable components to be very useful. I have also been blessed with working on some Classic ASP, which has got me thinking…

Could we create reusable components using Classic ASP?

I’ve had a bit of a play with a simple project structure that enables you to create some basic components. It is not as pretty as React (as you would expect), but it seems to get the job done!

How do we write a component?

The example components that I have created are very simple. They have only one publicly exposed function called Render. All this method does is return compiled HTML.
My first thought was to perhaps just build the HTML inside the Render function, but I wanted to enable all the nice snippets that I can use in Atom. So I separated out the HTML inside its very own file. This is then read by the Render method.

Alright, lets see the code!

The Header Component

The BodyContainer Component

The includes.asp file just includes all the components.

How do I add components to my page?

In the example project the components are used in the index.asp page. I have included Bootstrap just to make things look pretty.

Basically, all we are doing is a Response.Write and passing the returned HTML from the components Render function.

What next?

As I said in the beginning, this is just a very basic example of creating reusable components for Classic ASP. You could:

  • Create components that could take in some parameters to affect how the component is rendered.
  • Create a routing component that decides what child components it needs to render (trying to simulate a SPA???)

I’m not saying that this is a good idea…it was just something I was thinking about 😄