Events in Classic ASP
I am currently writing a MVC framework in my free time which I will be posting live within the next week after some testing. However this is a sneak peak at how awesome it is going to be. Classic ASP, as you know has not had an update from Microsoft since 1998 when they moved to .NET. Unfortunately, a lot of applications are still being written in this language and plenty still need to be maintained. This is some simple code that allows events similar to the “observer pattern”. The syntax on the index is a bit rough but I needed to pull it out of my framework’s core for an example. It will look prettier once the framework is released.
As you can see the basic syntax simply calls the eventQue file which is the class definition where the magic happens. The second file “pluginDemo1″ is a plugin who has 2 hooks one on “init’ and another on “destroy”. On this page we also call “init”.
<%
' Explicit
Option Explicit
%>
<!-- #include file="./libraries/eventQue.asp" -->
<%
' Variables
Dim events
Set events = new eventQue
%>
<!-- #include file="./plugins/demoPlugin1.asp" -->
<%
events.callHook("init")
%>
On the plugin page you will need to have a “getHooks” method which returns an array. You are also required to have a “trigger” function which has a string passed to it with which event was triggered. Only the triggers you specified will passed. We can’t call the function directly due to language restrictions.
<%
Class demoPlugin1
Public Function getHooks()
getHooks = array("init", "destroy")
End Function
Public Function trigger(hookName)
If hookName = "init" Then
myInitHook()
ElseIf hookName = "destroy" Then
Response.write("THE WORLD IS OVER!")
End If
End Function
Private Function myInitHook()
Response.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
End Function
End Class
Dim myPlugin
Set myPlugin = new demoPlugin1
events.addHooks(myPlugin)
Set myPlugin = Nothing
%>
This is the output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Discussion
No responses to "Events in Classic ASP"
There are no comments yet, add one below.
Leave a Comment