For each one. NET programmer, for the ASP.net page life cycle have a certain understanding and grasp. For some details please refer to http://blog.sina.com.cn/s/blog_5f7aa2970100d5h4.html, the content is more detailed, this article will no longer outline. This article mainly grasps and controls the overall page life cycle from inheritance and view state, events, delegates, container controls, and child controls.
First look at the following 4 related pages of code (to reduce complexity, a lot of code is truncated and streamlined, providing only the most basic operating code). Just a few files, first look at the overall layout of the document, there is a overall grasp.
(i) Related events of the parent class and handling
Code highlighting produced by Actipro Codehighlighter (freeware)
http://www. codehighlighter.com/
--> 1 public class UserParentPage:System.Web.UI.Page
{
///<summary>
///processing of return data, setting up of other content, obtaining
///</summary>
///<param name= "E" ></param>
protected override void OnInit (EventArgs e)
{
Core.Trace.TraceInfo ("Userparentpage OnInit");
Base. OnInit (e);
Write appropriate code to prevent SQL injection
//system.web.httpcontext.current.request.querystring/form
//detection based on context objects, and to make corresponding processing
//And some other content settings, controls, and so on
}
protected override void OnLoad (EventArgs e)
{
Core.Trace.TraceInfo ("Userparentpage OnLoad");
Base. OnLoad (e);
Write the appropriate code for the overall page control
}
}
(ii) Related content of user controls (child controls)
Code highlighting produced by Actipro Codehighlighter (freeware) http://www. codehighlighter.com/--> 1 Public partial class UserEventControl:System.Web.UI.UserControl {public
delegate void Changedhandler ();
public event Changedhandler Changed; private void Page_Load (object sender, System.EventArgs e) {Core.Trace.TraceInfo ("Usereventcontrol on
Load "); if (! Page.IsPostBack) {Core.Trace.TraceInfo ("Usereventcontrol OnLoad!")
Page.ispostback==true ");
SetContent ();
} private void SetContent () {int Len =12,num = 2,perrowmaxcount=8;
System.Text.StringBuilder table = new System.Text.StringBuilder (); for (int i = 0; I <= num; i++) {table.
Append (@ "<table bordercolor= ' black ' width= ' 100% ' ><tr ' left ' >"); for (int j = 0;J < Perrowmaxcount;
J + +) {int p = i * perrowmaxcount + j;
if (P < len) {string paramvalue = "param" +p.tostring ();
String showvalue = "Show" +p.tostring (); Table. Append (String. Format (@ "<td width= ' 12.5% ' ><a href= ' javascript:__dopostback '" ' {2} ' "'" ' {0} ' ") ' commandname= '" {0} "' class= ' Line ' ><font>{1}</font></a></td> ', Paramvalue,showvalue, LbtnShow.ClientID.Replace ("_
Lbtnshow "," $lbtnShow ")); } else {table. Append (String.
Format (@ "<td width= ' 12.5% ' ></td>")); }} table.
Append (@ "</tr></table>"); } lblshow.text = table.
ToString ();
public string CurrentID {set { viewstate["CurrentID"] = value;
get {return (string) viewstate["CurrentID"]; }} protected override void OnInit (EventArgs e) {Core.Trace.TraceInfo ("userevent
Control OnInit ");
InitializeComponent (); Base.
OnInit (e); private void InitializeComponent () {This.lbtnShow.Click + + new System.EventHandler (thi
S.lbtnshow_click); This. Load + = new System.EventHandler (this.
Page_Load); ///<summary>///Click will trigger///</summary>///<param name= "Sender" ></ param>///<param name= "E" ></param> private void Lbtnshow_click (object sender, System.event
Args e) {Core.Trace.TraceInfo ("Usereventcontrol Lbtnshow_click"); CurrentID = request.form["__eventargument"];//gets the postback value setcontent (//Set content----because some content has been modified, such as style or something, this example ignores Changed ();//Trigger event}}