Click here to Skip to main content
14,032,238 members
Click here to Skip to main content
Add your own
alternative version


57 bookmarked
Posted 7 Aug 2004

Classic ASP Framework 2.0 - Make your Classic ASP code work like in ASP.NET

, 7 Aug 2004
Rate this:
Please Sign up or sign in to vote.
The Classic ASP Framework (CLASP) will allow you to structure your ASP pages in the same way you do it with ASP.NET

Screen Shots









This is CLASP version 2.0 and a follow-up article for Classic ASP Framework The Classic ASP Framework allows you to structure your ASP pages in the same way you would do it in ASP.NET. It is fully event driven and has most of the controls you will ever need such as TexBoxes, CheckBoxes (and CheckBoxList), RadioButtons, Labels, DropDowns, Lists, DataGrids, DataRepeaters, DataLists, RichTextBoxes, Timers, Field Validators, Tabs and many more!

ViewState support (can be be overridden at the page level):

  • Client Side: in a hidden field.
  • Server Side: in a Session variable.
  • SQL Server: in a SQL Server table.
  • Custom: Write your own Viewstate perisistence handler!
  • Different implementations: COM (fastest) and pure ASP (a bit slower). Server Side and SQL Server don't require COM implementations.

Ability to register client side scripts and to register client side events from the server code.

For instance. Page.RegisterEventListener cmdSave,"onclick","TestFnc". All events are stacked/linked

and are called in a bubble like fashion, so you can have multiple event listeners for the same object!!!.

Other nice things are a PageController concept which allows you to structure your pages in a template-like fashion that supports role-level authentication and authorization.

What's new in version 2.0?

Too many things have changed and been improved to mention in this article. A few things are listed below:

  • Event model matches as much as possible to ASP.NET (Page level and Control life-cycle level)
  • Improved Speed - Big time.
  • Improvements to all controls. More properties and customization.
  • New controls such as RichTextBox, Timer, Panel, Validation Controls (just like in ASP.NET)
  • More configuration options such as pluggable viewstate persistence and implementations just to name a few.
  • More samples.
  • A sample site with help.
  • The PageController model to build template pages with support for role-level authentication/authorization.
  • Reusable JavaScript libraries (clasp, clasp.form,, clasp.validation)
  • etc etc etc

Do you want to see it in action? visit our samples site.


CLASP is ideal for developers that need maintain or create new ASP Pages. It will simplify your coding and make it a breeze to create new and maintain pages and when it is time to move to ASP.NET, it will take you a fraction of the time to port since the coding style is almost the same.

The main benefits are:

  • Coding takes a lot less time, code is more readable and easier to maintain.
  • Comprenhensive list of controls.
  • Flexible event driven model (Similar to AutoEventWireUp in ASP.NET)
  • Source code for EVERYTHING.
  • Is Open Source --- FREE ---
  • Simplifies the migration to ASP.NET.

Using the code

Using the code couldn't be any easier.

Structure of a Page

CLASP pages are structured in the following way (unless you use the page controller):

  1. Include the WebControl.asp page
  2. Include any WebControl file to be used by the page (i.e. Server_TextBox.asp)
  3. Include any extra file that your page will make use of.
  4. Execute the following ASP Code: Page.Execute
  5. Write your HTML. You can mix html with server controls (i.e.
    ) You MUST start the section where you will be rendering your HTML Form and where WebControls that render HTML input controls with this ASP Code: Page.OpenForm and end it with Page.CloseForm. This is critical these functions render the html form and include all the hidden fields that CLASP make use of.
  6. Your Code-Behind or Server Code is next and could be in a separate file or at the bottom of the page.
  7. Include your WebControl variable declarations (i.e.
    Dim txtFirstName, 
  8. Include your page-level variables (i.e. Dim mStatus)
  9. Add Public Function Page_Init() and initialize all the WebControls there (I.e. Set txtFirstName = New_ServerTextBox("txtFirstName") and module level variables (i.e. mStatus= 0)
  10. Add any other Page event that you want override such as Page_Controls_Init (happens only once and is ideal to initialize controls that have the viewstate enabled, code in this event will be executed only If Not Page.IsPostBack) , Page_Load, Page_LoadViewState, etc. Note: Keep in mind that viewstate is available only from Page_LoadViewState and any later event.
  11. Write your event handlers such as cmdSave_OnClick, txtFirstName_OnTextChange.
  12. Write your supporting functions.
  13. That is it!, you are done!.

Sequence of Events in CLASP

Looking at the Page.Execute -"Sub Main()"- routine in WebControl.asp will give you a very good idea of how CLASP process each request. A high level look at the life cycle of a CLASP page looks like this (you can override and handle the events highlighted in blue):

  • Page_Authenticate_Request
  • Page_Authorize_Request
  • Page_Init
  • If 
      Not Page.IsPostBack Then Page_Controls_Init 
  • If 
      Page.IsPostBack Then  Page_LoadViewState 
  • If 
      Page.IsPostBack Then  ProcessPostBackData 
  • Page_Load
  • If 
      Page.IstPostBack Then Page.HandleServerEvent "RaiseChangedEvents" 
  • If 
      Page.IsPostBack Then Page.HandleClientEvent
    (Handles the PostBack by executing the handler of the event)
  • Page_PreRender
  • Page_SaveViewState
  • Page_Terminate
Note : If you use the PageControler model you also have the following events: Page_Configure, Page_RenderHeader, Page_RendeForm, Page_RenderFooter and it will handle the Page_AuthenticateRequest and Page_AuthorizeRequest automatically. The CLASP sample site has an example of an implementation using the page controller.

The Life Cycle of a Control is: (this happens automatically and is transparent)

  • Class_Initialize
  • OnInit - You need to subscribe to receive this event -
  • ReadProperties(v) - Only if EnableViewState = True
  • OnLoad - You need to subscribe to receive this event -
  • ProcessPostBack - You need to subscribe to receive this event -
  • HandleClientEvent(e)  
    -Only if Target of the postback event
  • WriteProperties(v) -Only if EnableViewState = True
  • Render
  • Class_Terminate

Here is a code sample. For those of you that are already programming in ASP.NET you will find the the code looks very much like an ASP.NET page (with some obvious differences...).

<!--<span class="code-comment">#Include File = "..\WebControl.asp"        --></span>
<!--<span class="code-comment">#Include File = "..\Server_Button.asp" --></span>
<!--<span class="code-comment">#Include File = "..\Server_CheckBox.asp" --></span>
<!--<span class="code-comment">#Include File = "..\Server_DropDown.asp" --></span>
<!--<span class="code-comment">#Include File = "..\Server_Label.asp"    --></span>
<!--<span class="code-comment">#Include File = "DBWrapper.asp"    --></span>

<LINK rel="stylesheet" type="text/css" href="Samples.css">
<!--<span class="code-comment">#Include File = "Home.asp"        --></span>
<Span Class="Caption">DROPDOWN EXAMPLES</Span>
  <%chkHideShow%> | <%chkAutoPostBack%> | <%chkListBox%><HR>
  <%cmdAdd%> | <%cmdRemove%>


'--Controls Declaration

  Dim lblMessage
  Dim cmdAdd
  Dim cmdRemove  
  Dim chkHideShow
  Dim chkAutoPostBack
  Dim chkListBox
  Dim cboDropDown

'--Page Events
  Public Function Page_Init()
    Page.DebugEnabled = False ' True/False
    Set lblMessage = New_ServerLabel("lblMessage")
    Set cmdAdd = New_ServerLinkButton("cmdAdd")
    Set cmdRemove = New_ServerLinkButton("cmdRemove")            
    Set chkHideShow = New_ServerCheckBox("chkHideShow")
    Set chkAutoPostBack = New_ServerCheckBox("chkAutoPostBack")
    Set chkListBox= New_ServerCheckBox("chkListBox")
    Set cboDropDown = New_ServerDropDown("cboDropDown")
  End Function

  Public Function Page_Controls_Init()
    cmdAdd.Text = "Add"
    cmdRemove.Text = "Remove"

    lblMessage.Control.Style = "border:1px solid blue;
    lblMessage.Text = "This is an Example"
    chkHideShow.Caption = "Hide/Show List"
    chkHideShow.AutoPostBack = True
    chkAutoPostBack.Caption = "DropDown AutoPostBack"
    chkListBox.Caption = "Make it a list box"
    chkListBox.AutoPostBack = True
    cboDropDown.DataTextField = "TerritoryDescription"
    cboDropDown.DataValueField = "TerritoryID"
    Set cboDropDown.DataSource = GetRecordset(
"SELECT TerritoryID,TerritoryDescription FROM Territories ORDER BY 2")    
    cboDropDown.DataBind() 'Loads the items collection 
              '(that will stay in the viewstate)...
    Set cboDropDown.DataSource = Nothing 'Clear
    cboDropDown.Caption = "Territory:"
    cboDropDown.CaptionCssClass = "InputCaption"
  End Function
  Public Function Page_PreRender()
    Dim x,mx
    Dim msg 
    Set msg = New StringBuilder
    msg.Append "<B>Selected Value=</B>" 
        & cboDropDown.Items.GetSelectedText  &  "<BR>"
    msg.Append "<B>Selected Text=</B>" 
       & cboDropDown.Items.GetSelectedValue  &  "<BR>"

    msg.Append "<HR>"
    mx = cboDropDown.Items.Count -1    
    lblMessage.Text  = msg.ToString()    
  End Function

'-- PostBack Handlers

  Public Function chkHideShow_Click()
    cboDropDown.Control.Visible = Not cboDropDown.Control.Visible
  End Function

  Public Function chkAutoPostBack_Click()
    cboDropDown.AutoPostBack = chkAutoPostBack.Checked
  End Function

  Public Function cmdAdd_OnClick()
    cboDropDown.Items.Add cboDropDown.Items.Count,
  End Function

  Public Function cmdRemove_OnClick()
    cboDropDown.Items.Remove cboDropDown.Items.Count-1
  End Function

  Public Function chkListBox_Click()
    if chkListBox.Checked Then
      cboDropDown.Rows = 10
      cboDropDown.Multiple = True
      cboDropDown.Rows = 1
      cboDropDown.Multiple = False
    End If
  End Function    

Points of Interest


  • The current version is 2.0 (production stable)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Christian Calderon
Web Developer
United States United States
Christian is a Microsoft Certified Professional 8+ years of experience in the consulting business. He has designed and developed numerous Web and Windows applications (and many other things he doesn't even remember...) using technologies and tools such as ASP.NET,VB.NET, C#, ASP, COM+/MTS, C++, JavaScript, HTML/DHTML, Visual Basic, SQL Server, Oracle, Microsoft Access, etc.

He is quite "curious" and always wants to know how things work and the "why was it done like this or that, how does this works...", and because of this he is always pursuing to improve his skills so he can know the answers to these questions.

He also likes Martial Arts, finishing and spending time with his wife and daughter. And why not?, playing XBOX from time to time :-P

Christian works as the Microsoft Technologies Manager/Senior Developer for Electronic Knowledge Interchange, a Chicago based Technology Consulting Firm.

You may also be interested in...


Comments and Discussions

QuestionDocumentation and examples? Pin
Strider7220-Oct-17 8:35
memberStrider7220-Oct-17 8:35 
Questionnot found Pin
kiquenet.com3-Oct-17 4:39
professionalkiquenet.com3-Oct-17 4:39 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey31-Mar-12 0:41
professionalManoj Kumar Choubey31-Mar-12 0:41 
QuestionHow to set up in IIS7.5 Pin
MiniDevCH9-Oct-11 5:53
memberMiniDevCH9-Oct-11 5:53 
AnswerRe: How to set up in IIS7.5 Pin
kiquenet.com27-Sep-17 11:38
professionalkiquenet.com27-Sep-17 11:38 
Generalcalling datagrid script fails to pick up posted variables the first time Pin
squeek17-Jun-11 5:48
membersqueek17-Jun-11 5:48 
GeneralIs not working in frames Pin
José Rogério Nakamoto22-Dec-09 1:18
memberJosé Rogério Nakamoto22-Dec-09 1:18 
GeneralRe: Is not working in frames Pin
kiquenet.com3-Oct-17 20:07
professionalkiquenet.com3-Oct-17 20:07 
GeneralCookies problem Pin
José Rogério Nakamoto21-Dec-09 5:56
memberJosé Rogério Nakamoto21-Dec-09 5:56 
GeneralRe: Cookies problem Pin
kiquenet.com3-Oct-17 20:06
professionalkiquenet.com3-Oct-17 20:06 
Generalerror on all pages Pin
SteveMets1-Jul-09 6:17
professionalSteveMets1-Jul-09 6:17 
GeneralRe: error on all pages Pin
Christian Calderon9-Jul-09 4:39
memberChristian Calderon9-Jul-09 4:39 
GeneralRe: error on all pages Pin
SteveMets9-Jul-09 13:26
professionalSteveMets9-Jul-09 13:26 
QuestionDoes anyone have a small sample of how to set this up in VS 2008? Pin
SteveMets9-Jun-09 10:48
professionalSteveMets9-Jun-09 10:48 
AnswerRe: Does anyone have a small sample of how to set this up in VS 2008? Pin
Christian Calderon13-Jun-09 16:58
memberChristian Calderon13-Jun-09 16:58 
GeneralRe: Does anyone have a small sample of how to set this up in VS 2008? Pin
SteveMets13-Jun-09 21:15
professionalSteveMets13-Jun-09 21:15 
GeneralRe: Does anyone have a small sample of how to set this up in VS 2008? Pin
SteveMets30-Jun-09 12:02
professionalSteveMets30-Jun-09 12:02 
GeneralNew Download Site Pin
Christian Calderon16-Jan-09 4:05
memberChristian Calderon16-Jan-09 4:05 
QuestionIs this project still active? Pin
TriLogic219-Nov-08 8:35
memberTriLogic219-Nov-08 8:35 
AnswerRe: Is this project still active? Pin
Christian Calderon24-Nov-08 17:25
memberChristian Calderon24-Nov-08 17:25 
GeneralRe: Is this project still active? Pin
José Rogério Nakamoto24-Nov-08 21:42
memberJosé Rogério Nakamoto24-Nov-08 21:42 
GeneralRe: Is this project still active? Pin
Jakob "XnaFan" Krarup29-Nov-08 12:30
memberJakob "XnaFan" Krarup29-Nov-08 12:30 
GeneralRe: Is this project still active? Pin
snashter10-Dec-08 3:50
membersnashter10-Dec-08 3:50 
GeneralRe: Is this project still active? Pin
andy dooley11-Dec-08 14:05
memberandy dooley11-Dec-08 14:05 
GeneralRe: Is this project still active? Pin
dadot227-Dec-08 6:20
memberdadot227-Dec-08 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190419.4 | Last Updated 8 Aug 2004
Article Copyright 2004 by Christian Calderon
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid