Library tutorials & articles
Make your Classic ASP code work like in ASP.NET
Using the Code
Using the code is fairly simple. Just include the "WebControl.asp" file and a reference to each Server Control (example: Server+CheckBox.asp) that you want to use to your ASP page. After you include the references then you need to write code inside each event you want to handle (Page level or postback events).
Include FormStart.asp when the form starts and FormEnd.asp when you need to close the form tag. This two includes will make sure that all necessary hidden fields are included. The last thing that has to be done is to the Main() method (included in the WebControls.asp). This method will do the magic. I call it the "Page Controller" because it coordinates the execution of all the events in the appropriate order. This method should only be called after the declaration of all the includes and BEFORE rendering any control.
The Framework includes several examples that show how it works. WebControl.asp contains the core classes: WebControl, ControlsCollection, Page, ClientEvent and a few utility functions. All controls "inherit" from WebControl (including the Page class). Now, wait a second, inherits in VBScript?. Not really, I "simulated" inheritance by having each WebControl variable inside each Server Control.
In addition to this, you need to register one COM Comnponent (ASPFramework.dll) which is used to encapsulate the ViewState (which is XML), the Base64 functions and the ListItemCollection. It is a VB Class and the source code is provided. The only reason for using a VB Class is for speed purposes. We don't want to encrypt/decrypt in VBScript!
Below is the list of events that are currently supported at the page level (if they are present then they will be executed)
-
Page_Authenticate_Request -
Page_Authorize_Request -
Page_Init -
Page_Controls_Init- Occurs just once, when the page is first loaded! -
Page_LoadViewState -
Page_Load -
Page_HandleClientEvent -
Page_PreRender -
Page_SaveViewState
This are the events supported by custom Server Controls (when creating your own controls). Look at one of the controls such as Server_CheckBox or Server_HyperLink to see how easy is to write your own control!
-
OnInit -
OnLoad -
ReadProperties(PropertyBag)- To read your persisted properties in the viewatate -
WriteProperties(PropertyBag)- To write your properties to the viewstate -
HandleClientEvent(event)- To handle events if the object is target of a postback
Other cool features are
-
Page.AutoResetScrollPosition- used to restore the vertical scroll position between postbacks -
Page.AutoResetFocus- used to reset the focus to the last control souce of a postback (which can be overrided!) -
Page.DebugEnabled- To keep track of a bunch of information that is displayed at the end of the page (like tracing in .NET). You control the details level usingPage.DebugLevel(1-3) -
Page.CompressFactor- Set to-1for no compress, and> 0to compress if ViewState size> CompressFactorbytes -
Page.ViewstateMode- used to control the location of the viewstate. Can be set toVIEW_STATE_MODE_CLIENTorVIEW_STATE_MODE_SERVER. IfVIEW_STATE_MODE_SERVERthen the viewstate will be persisted in the VS session variable! -
Page.IsRedirectedPostBack- This property indicates if the page was called from another asp page and it has event information in the form... VERY useful to pass parameters between pages and avoid the use of the QueryString!
The postback events are usually captured by writing a function using the following format: controlName_eventName([event]). For instance, if you click on button with name cmdSave then you would capture this event on the server side by creating a function such as: cmdSave_OnClick()
The Framework supports viewstate, so you can use Page.ViewState.Add(key,value) and Page.ViewState.GetValue(key). Each control also supports viewstate through Control.EnableViewstate = (true/false)
On the next few pages, we'll show a few screen shots, and the source code that was used to create them.
Related articles
Related discussion
-
How to debug classic ASP pages during AJAX calls in ASP.NET website
by andwan0 (0 replies)
-
Menu.css corrupting my other theme.css
by Montague (0 replies)
-
GridView cell colour change
by viral.mat (1 replies)
-
need Regular Expression for strong password
by bussureddy82 (4 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
Related podcasts
-
Developer's Guide to IIS7
Steve Schofield is an IIS expert working for webhost ORCS Web. Steve and his team are responsible for such sites as Channel9, ASP.NET, weblogs.asp.net and ASP Alliance. As a member ASP Insiders and a IIS MVP - Steve knows his way around a web server. Steve sheds light on how the new features in I...
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
Hi. I have several ASP 3.0 to EXCEL 10.0 reports thaqt work fine. When I try to go to EXCEL 11.0, I get an invalid class. How do I set that up for my object?
Thanks,Mac Kimsey mackimsey@yahoo.com
http://clasp.csharpjunkie.com/
This thread is for discussions of Make your Classic ASP code work like in ASP.NET.