how to properly encode a URL (e.g. used in javascript or css includes)
how to display context information for template parsing and instantiation? File name? line number?
how to do this for Theme (skin files)?

think more about encoding/decoding
<%@ MasterClass="Pages.MasterPage" %>


Features to be implemented later:
- SmartNavigation: TForm, TPage

Main Problems:
1. How to solve viewstate ID mapping problems? What if a control has changed its ID before saving viewstate?
5. What if in a getter, it needs to address a sibling or child control?
6. learn more details about WebParts
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_northwindwebparts.asp

When a page is requested, asp.net 2.0 does the following
- application creates the page instance by new operator
- application invokes page.processrequest
- page.frameworkinitialize is invoked
- ... ControlBuilder.InitObject(page)
- ... ... set SkinID
- ... ... apply stylesheet skin
- ... ... init simple properties (basic property types)
- ... ... init complex proprerties (e.g. Font-Name), may need to call InitObject on Font
- ... ... init data bindings
- ... ... call BuildChildren if item implements IParserAccessor (Control implements it)
- ... ... ... for each body item
- ... ... ... ... get the control builder for the control class
- ... ... ... ... call ControlBuilder.BuildObject
- ... ... ... ... ... call InitObject
- ... ... ... ... if it is user control (control with template)
- ... ... ... ... ... call UserControl.InitializeAsUserControl(page)
- ... ... ... ... ... ... call frameworkinitialize (won't call InitObject anymore)
- ... ... ... ... call control.AddParsedSubObject(item)
- ... ... init template properties (should be a property with template type, will use TemplateBuilder to build the object)
- ... ... bind field to control (pass some fields from TemplateControl to the new control)

How is a UserControl initialized if created dynamically?
- ... InitializeAsUserControl invoked in OnInit (which will be caught up if the control is dynamically created)




Findings:


Control lifecycles:

const CS_CONSTRUCTED=0;				// after constructor
const CS_FRAMEWORK_INITIALIZED=1;	// after children created and properties set
const CS_CHILDREN_INITIALIZED=2;	// right before OnInit (also before applySkin, but after children OnInit)
const CS_INITIALIZED=3;				// right after OnInit
const CS_STATE_LOADED=4;			// right after loading state
const CS_LOADED=5;					// right after loaded
const CS_PRERENDERED=6;				// right after prerender

stylesheet is applied before setting control properties (after skinID is set)
skin is applied right before OnInit



ControlBuilder is responsible to call AddParsedSubObject
Its BuildChildren is

My understanding of lifecycles:

Page constructed (using new operator)
Page.ProcessRequest
  Page.FrameworkInitialize
    Page.InitializeStyleSheet
  Page.determinePostBackMode
  Page.loadScrollPosition
  Page.performPreInit
  Page.initRecursive
  Page.onInitComplete
  Page.loadAllState
  Page.processPostData
  Page.onPreLoad
  Page.loadRecursive
  Page.processPostData
  Page.raiseChangedEvents
  Page.raisePostBackEvent
  Page.onLoadComplete
  Page.raiseCallBackEvent -> exit
  Page.preRenderRecursive
  Page.performPreRenderComplete
  Page.saveAllState
  Page.onSaveStateComplete
  Page.renderControl
  Page.unloadRecursive


Possible solution for SkinID: setting SkinID will cause skin change immediately.
With control hierarchy storing:


Page constructed (template parsed but not instantiated)
Page.loadAllState <---- page state totally restored
Page.loadRecursive
Page.processPostData
Page.raiseChangedEvents
Page.raisePostBackEvent  or Page.raiseCallBackEvent
Page.preRenderRecursive
Page.saveAllState
Page.renderControl
Page.unloadRecursive



Page constructed
Page.frameworkInitialize (instantiating template)
Page.initRecursive
Page.saveAllState
Page.renderControl
Page.unloadRecursive




edit distance.
(UIUC) Jiawei Han: graph similarity mining

module service?
page service?


index.php?page=path.to.page


TODOs

renderer??
Dispose
-->> viewstate id-based or index-based, structure keeping?? <<--
HttpContext, url/path
template path
adapter
parser


class metadata attributes:
e.g. the body content of a control can be parsed as child controls, or property values
or list items

Imagine a usecase (hmmm...could have problem....) How to specify two list properties for a single control?
<com:TListBox>
<ID>abc</ID>
<Items>
  <ListItem Value="yyy">xxx</ListItem>
  <ListItem>yyy</ListItem>
</Items>
</com:TListBox>


how to define a control with template??
TemplateControl.LoadControl  or LoadTemplate is used for controls that allows taking template contents for their attributes.


UserControl! starting from the template instead of class



idNotCalculated = 1;
marked = 2;
disableViewState = 4;
controlsCreated = 8;
invisible = 0x10;
visibleDirty = 0x20;
idNotRequired = 0x40;
isNamingContainer = 0x80;
creatingControls = 0x100;
notVisibleOnPage = 0x200;
themeApplied = 0x400;
mustRenderID = 0x800;
disableTheming = 0x1000;
enableThemingSet = 0x2000;
styleSheetApplied = 0x4000;
controlAdapterResolved = 0x8000;
designMode = 0x10000;
designModeChecked = 0x20000;
disableChildControlState = 0x40000;
isWebControlDisabled = 0x80000;
controlStateApplied = 0x100000;
useGeneratedID = 0x200000;

TODO:

clean up ID, namingcontainer things:

A control can be added into page hierarchy in the following ways
- newly created in template
  - manual ID
  - need automatic ID
- dynamically created in code
  - manual ID
  - need automatic ID
- a previously removed control
  - manual ID
  - need automatic ID
When a control changes its ID, the following things are necessary:
- If it is a namingContainer
  - all its descendant must update their unique ID
- If it is a normal control, nothing needs to be done
- In both cases, the namingContainer's nametable has to be updated
When a control changes its page, ...?
- All its children have to change the page too
When a control changes its parent, ...?
-  This is like remvoedControl + addedControl.
When a control changes its namingcontainer ...?
- All its child controls have to change namingcontainer recursively
  The old namingContainer nametable must also be changed recursively.
When a control changes its templateControl...??
- Nothing to be done.



ControlState
============
Constructed
Initialized
ViewStateLoaded
Loaded
PreRendered



asp.net 2.0 lifecycles
========================
Application: BeginRequest
Application: PreAuthenticateRequest
Application: AuthenticateRequest
Application: PostAuthenticateRequest
Application: PreAuthorizeRequest
Application: AuthorizeRequest
Application: PostAuthorizeRequest
Application: PreResolveRequestCache
Application: ResolveRequestCache
Application: PostResolveRequestCache
Application: PreMapRequestHandler
Page: Construct
Application: PostMapRequestHandler
Application: PreAcquireRequestState
Application: AcquireRequestState
Application: PostAcquireRequestState
Application: PreRequestHandlerExecute
Page: AddParsedSubObject
Page: CreateControlCollection
Page: AddedControl
Page: AddParsedSubObject
Page: AddedControl
Page: ResolveAdapter
Page: DeterminePostBackMode
Page: PreInit
Control: ResolveAdapter
Control: Init
Control: TrackViewState
Page: Init
Page: TrackViewState
Page: InitComplete
Page: LoadPageStateFromPersistenceMedium
Control: LoadViewState
Page: EnsureChildControls
Page: CreateChildControls
Page: PreLoad
Page: Load
Control: DataBind
Control: Load
Page: EnsureChildControls
Page: LoadComplete
Page: EnsureChildControls
Page: PreRender
Control: EnsureChildControls
Control: PreRender
Page: PreRenderComplete
Page: SaveViewState
Control: SaveViewState
Page: SaveViewState
Control: SaveViewState
Page: SavePageStateToPersistenceMedium
Page: SaveStateComplete
Page: CreateHtmlTextWriter
Page: RenderControl
Page: Render
Page: RenderChildren
Control: RenderControl
Page: VerifyRenderingInServerForm
Page: CreateHtmlTextWriter
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose
Application: PostRequestHandlerExecute
Application: PreReleaseRequestState
Application: ReleaseRequestState
Application: PostReleaseRequestState
Application: PreUpdateRequestCache
Application: UpdateRequestCache
Application: PostUpdateRequestCache
Application: EndRequest
Application: PreSendRequestHeaders
Application: PreSendRequestContent