WebControl.asp V 2.0

File Name: WebControl.asp
Class Name: WebControl

Overview
Defines the methods, properties and events that are common to all server controls. The CLASP Framework iteracts with the server controls at the WebControl level.


Public Constructors
WebControl The constructor registers the control in the CLASP Framework by adding it to the Page's controls colleaction. The constructor also sets the detaults.

Public Properties
Name String The name of the control is required and has to be set on the Page_Init event. Normally you use the same name as the variable (i.e. txtFirstName)
ControlID String This property should be used when the control developer or the devoper wants to access the id of the control (** don't use the control name property!!!, you could, but is slower **)
EnableViewState Boolean Determines whether or not the underlying/implementing control supports viewstate. This is used by CLASP to determine if it will invoke the ReadProperties and WriteProperties so the control can restore/persist the state.
Enabled Boolean The use/interpretation of this property is delegated to the implementing control.
Visible Boolean The use/interpretation of this property is delegated to the implementing control.
Style String The use/interpretation of this property is delegated to the implementing control.
Attributes String The use/interpretation of this property is delegated to the implementing control.
CssClass String The use/interpretation of this property is delegated to the implementing control.
TabIndex Int The use/interpretation of this property is delegated to the implementing control.
ToolTip String The use/interpretation of this property is delegated to the implementing control.
DataTextField String If set to a value, then if Page.DataBind is executed it will invoke the SetValueFromDataSource method of the implementing control.
IsViewStateRestored Boolean Determines whether or not the viewstate for this control has been already restored.
ImplementsOnInit Boolean Determines whether or not the implementing control implements the OnInit event. If true, the CLASP will invoke this event right after Page_Init() completes.
ImplementsOnLoad Boolean Determines whether or not the implementing control implements the OnLoad event. If true, the CLASP will invoke this event right after Page_Load() completes.
ImplementsProcessPostBack Boolean Determines whether or not the implementing control implements the ProcessPostBack event. If true, the CLASP will invoke this event right after Page_LoadViewState() completes. This is normally used by controls that render html input controls so they can restore their postback values.
IsVisible Boolean Used to determine if the Control is visible by inspecting the visibility flag bin the hierarchy of controls, if any.
Parent WebControl Used to Get/Set the control immediate parent in the control hierarchy.
ViewState PropertyBag Reference to the internal property bag (which reports to the page viewstate).
OverrideTemplate Boolean If true then when applying a template/skin to the page the control will be by-passed. This allows the developer to use a different style than the one defined in the template.
ToolTipText String Use is determined by the implementing control.

Public Methods
-- --

Public Events
-- --

Protected Properties
Owner Object Hold a reference to the implementing control. Every User Control has to have a WebControl inside (sort of the way of implementing "inheritance" in Classic ASP). This is important and has to be set by the implemeting control in order for the WebControl to comunicate and raise internal events.

Protected Methods
ReadProperties(vs) Implemented by the WebControl and used to restore the WebControl state. Accepts a viewstate object. This is part of the CLASP Framework and should not be directly used
ReadProperties(bag) Implemented by the Implementing control and used to restore the control-specific state. Accepts a PropertyBag object.
WriteProperties(vs) Implemented by the WebControl and used to persist/save the WebControl state. Accepts a viewstate object. This is part of the CLASP Framework and should not be directly used
WriteProperties(bag) Implemented by the Implementing control and used to persist/save the control-specific state. Accepts a PropertyBag object.
RestoreViewState Implemented by the WebControl and used to restore the WebControl state. This is used by Web Controls created dynamically AFTER the Page_Init event. This is part of the CLASP Framework and should not be directly used
ProcessPostBack Implemented by the implementing control and is used to restore the values posted back. Controls also make use of this event to register OnChanged events.

Protected Events
HandleServerEvent(EventName) If implemented by the Implementing control then the CLASP uses it nofity the object that it has been target of a server-side event.This is part of the CLASP Framework and should not be directly used
HandleClientvent(EventName) If implemented by the Implementing control then the CLASP uses it nofity the object that it has been target of a client-side event. This is part of the CLASP Framework and should not be directly used



Example of a control implementing the WebControl

	Public Function New_ServerControlTemplate(name) 
		Set New_ServerControlTemplate =
	  New 
		ServerControlTemplate New_ServerControlTemplate.Control.Name =  name
			End  Function
	Page.RegisterLibrary "your
	
	library name"
	
	Class ServerControlTemplate
		Dim Control
		Dim YourVariable		
		
		Private Sub Class_Initialize()
			
			Set Control =
	
	New WebControl
			'Set Controls
		= new		
		
		ControlsCollection 'Only if
			
			control is a container... Set	
			Control.Owner = Me 'Only if control is a container... if not
			don't expose it! (they 			can get to it anyway) 'Initialize your internal variables YourVariable = "" Control.ImplementsOnInit = True '? If
			
			you want the OnInit
			to be called
			Control.ImplementsOnLoad = True '?  If you want the Onload to be called
			Control.ImplementsProcessPostBack = True '?  If you want to receive a ProcessPostBack notification
			on postbacks for form inputs End Sub Public Sub OnInit() 'At this stage of the game,
	   the viewstate
	   
	   	is not yet			
	   		loaded but all the controls 'are initialized. This can be used to add dynamic controls to
	   		this control (for more complex controls) End Sub Public Sub OnLoad() 'View state is ready and controls
		are ready.

	   	In here you			
			can make decisions or update calulated fields. 'After this, the page load will be called 'If you need
			to register any client script (js code) you
			
			can do it using 'Page.RegisterClientScript(scriptname,scriptcode) 'I don't have one to register a script using the
			source=...
			put it can be easily done. End Sub Public Function SetValueFromDataSource(value) 'If you support Data Binding (Page.DataBind)
		then use
		
	   this method to
		capture the binded value. 'i.e. YourValue = value 'The WebControl has a property called DataTextField
		(Control.DataTextField) that can be
		
		used to specify 'the name of the field to be used during the bind
		procedure. 'In the page the developer has to invoke Page.DataBind(DataSourceRecordSet,Nothing) (to bind
		at the page level) 'Check the code in WebControl.asp. Right now is a flat databind
		and is not navigating the hierarchy. Just comment out 'a line in the WebControl.asp Page.DataBind to support hierarchical databind. End
		Function Public Function ReadProperties(bag) 'If the control supports viewstate (you
				
	   want to
	   
	   read persisted data
			in between requests) 'The bag variable is a property bag object. To see its 
			methods go to the WebControl.asp 'For boolean values you can use ReadBoolean, for Integers ReadInt and
			so on. YourVariable = bag.Read("YV") End Function Public Function WriteProperties(bag) 'If the control
			
			supports viewstate (you
	   want to
		
	   persist data in
			between requests) bag.Write "YV",YourVariable End Function Public Function ProcessPostBack() 'Use Control.ViewState if you 
			want to
	   gain access

	   to the viewstate.
			'It will  be = Nothing EnableViewState = False OR if the 
			control was created AFTER or during page page_loadviewstate
	   End Function	    
	   Public Function HandleClientEvent(e)
			'e is of type  ClientEvent (see WebControl.asp for methods and properties)
			
			HandleClientEvent = True 'To signal callee the receipt ak.
			'You can just call the "
			HandleClientEvent = ExecuteEventFunctionEX(e)
			
			'Check the ExecuteEvent functions in WebControl.asp for more ways to handle events
			
			'or you could determine the event name (e.EventName) and handle it internally.
			
	   End Function					
		
	   Private Function RenderMe()
			Response.Write "I'm rendering myself! and by the way, YourValue is " & YourValue
			'To aquire a postback event code you must use the following series of functions:
			'Page.GetEventScript(ClientTrigger, ObjectName, EventName, ByVal Instance, ExtraMessage)
			'(and all its variations  ... check them in webcontrol.asp)
			'The ClientTrigger is the javascript event, ObjectName is the ID of the object target of the event, EventName is self explanatory
			'Instance is anything you want to pass back to the page (used normally when there is more than one control or in a link so can pass the id of something)
			'The ExtraMessage is anything EXTRA that you can to pass... :-P
			
	   End Function
	   
	   Public Default Function Render()			
			 Dim varStart	 
			 			 
			 'You are responsible to handle the meaning of "visibility". It could be as simple as exiting the function
			 
			 If Control.IsVisible = False Then
				Exit Function
			 End If
			 
			 varStart = Now
			 
			 'You may want to handle the rendering process in another private function, to keep this one small
			 Call RenderMe()
			 
			 'Be a nice boy and tell us how long did it take this control to render. This is used for debugging purposes...
		 	 Page.TraceRender varStart,Now,Control.Name
		 	
		 	 'You can always add to the trace
		 	 'If you want to relate the message to the object: Page.TraceCall(Control,Message)
		 	 'Or just to add a message Page.TraceCall(Method,Message)
		 	 'To highlite the message Page.TraceImportantCall(Control,Message)
		 	 'Or to the error:Page.TraceError
		
			 'The Control object (WebControl) has a tab index that you can use to specify the tab index.
			 'If you want the framework to assign it based on the render order use 
			 'Control.TabIndex = Page.GetNextTabIndex()
		 	 
		 	 'Need to keep the vertical scroll position? then Page.AutoResetScrollPosition = True
	   End Function
			   	

	End Class