asp.net: Viewstate and dynamically added controls

satya - Thursday, May 17, 2007 10:24:36 AM

start with this article from Scott Mitchell

start with this article from Scott Mitchell

satya - Thursday, May 17, 2007 10:25:18 AM

Understanding ASP.NET View State

Understanding ASP.NET View State

satya - Thursday, May 17, 2007 10:27:56 AM

where can I find the code generated by asp.net?


WINDOWS\Microsoft.NET\Framework\Version\Temporary ASP.NET

satya - Thursday, May 17, 2007 10:28:53 AM

basic page life cycle


Instantiation, 
Initialization, 
Load View State, 
Load, 
Save View State

satya - Thursday, May 17, 2007 10:29:42 AM

The init stage

All controls init method gets called

satya - Thursday, May 17, 2007 10:35:17 AM

The wisdom of scott

If we need our dynamically added controls to maintain their view state it is paramount that these controls be added before the Load View State stage. That is, these controls must exist within the page's control hierarchy before the view state is loaded. There's only one stage before Load View State - Initialization. That means, if we want our dynamic controls to persist view state we must add them to the control hierarchy in the page's Init event.

satya - Thursday, May 17, 2007 10:52:18 AM

Working with Dynamically Created Controls

Working with Dynamically Created Controls

satya - Thursday, May 17, 2007 10:55:28 AM

ASP.NET Page Life Cycle Overview

ASP.NET Page Life Cycle Overview

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you intend. Additionally, if you develop custom controls, you must be familiar with the page life cycle in order to correctly initialize controls, populate control properties with view-state data, and run any control behavior code. (The life cycle of a control is based on the page life cycle, but the page raises more events for a control than are available for an ASP.NET page alone.)

satya - Thursday, May 17, 2007 11:01:38 AM

HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET

HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET

satya - Thursday, May 17, 2007 11:02:42 AM

How is page_init being utilized for this


Private Sub 
Page_Init(ByVal sender As System.Object, 
     ByVal e As System.EventArgs) 
Handles MyBase.Init

    ' Create dynamic controls here.
    TextBox1 = New TextBox()
    TextBox1.ID = "TextBox1"
    TextBox1.Style("Position") = "Absolute"
    TextBox1.Style("Top") = "25px"
    TextBox1.Style("Left") = "100px"
    Form1.Controls.Add(TextBox1)

    TextBox2 = New TextBox()
    TextBox2.ID = "TextBox2"
    TextBox2.Style("Position") = "Absolute"
    TextBox2.Style("Top") = "60px"
    TextBox2.Style("Left") = "100px"
    Form1.Controls.Add(TextBox2)

    ' CODEGEN: The Web Form Designer requires this method call.
    ' Do not modify it by using the code editor.
    InitializeComponent()
End Sub

satya - Thursday, May 17, 2007 11:05:08 AM

Understanding the Page Life Cycle in ASP.NET - Joydip Kanjilala

Understanding the Page Life Cycle in ASP.NET - Joydip Kanjilala

satya - Thursday, May 17, 2007 11:05:30 AM

A complete list of methods


Page_Init 
LoadViewState 
LoadPostData 
Page_Load 
RaisePostDataChangedEvent 
RaisePostBackEvent 
Page_PreRender 
SaveViewState 
Page_Render 
Page_UnLoad

satya - Thursday, May 17, 2007 11:12:31 AM

example of an oninit vs page_init


protected override void OnInit(EventArgs args) { 
 
this.lstStates.DataSource = QueryDatabase(); 
 
this.lstStates.DataBind(); 
  
base.OnInit(e); 
 
}

satya - Thursday, May 17, 2007 11:23:21 AM

which is better oninit or page_init?

which is better oninit or page_init?

satya - Thursday, May 17, 2007 11:26:54 AM

Event Handling in ASP.NET...

Event Handling in ASP.NET...

satya - Thursday, May 17, 2007 11:27:40 AM

This answers the question between oninit and page_init

Each class that publishes an event also provides a protected, virtual method that raises the event. When the specific incident occurs the publisher class invokes this method. The task of this method is to notify all the event subscribers about the event. The event raising methods are identifiable via their naming convention ? the word 'On' followed by the name of the event, e.g. OnPreRender.