Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Help! Control Execution Lifecycle


Message #1 by "Lynn Curtner" <lynn.curtner@p...> on Mon, 22 Apr 2002 15:32:39
I'm struggling to understand the "Control Execution Lifecycle".  
Specifically: I'm dynamically creating a TextBox <see code below> during 
the page Load event, and when the user enters text into this TextBox and 
submits the page back to the server, that text is persisted across the 
postback.  This is just the behavior that I want, but I don't understand 
how it can happen, since according to the documentation of the "Control 
Execution Lifecycle", the "Load View State" phase takes place before the 
page Load event, at which time my TextBox is not even created!  How can 
this ViewState data be loaded into a control that doesn't exist?  Any 
insight into what's going on here would be greatly appreciated.

TIA,
Lynn Curtner

<code...>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ViewStateQuestion
{
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Table Table1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			TableCell MyTableCell = new TableCell();
			TextBox MyTextBox = new TextBox();
			MyTableCell.Controls.Add(MyTextBox);
			TableRow MyTableRow = new TableRow();
			MyTableRow.Cells.Add(MyTableCell);
			Table1.Rows.Add(MyTableRow);
		}

		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler
(this.Page_Load);

		}
	}
}

  Return to Index