ASP.NET Controls Status Conversion Memo

xiaoxiao2021-03-06  114

The following code can still keep 5 item: private void page_load (object sender, system.eventargs e) {ddl = new dropdownload (); if (! ISPOSTBACK) {for (int i = 0; i <5; i ) {ddl.items.add (i.tostring ());}}} Site, if it is: one start is a new object, in the original state, When it is added to the Controls of the parent, the parent control calls some methods of the child control according to its current Control phase, allowing the child control to catch the Control phase of the parent control (these methods can be left from the last post Leighsword and Microhelper's Control's AddedControl method sees, it is not repeated here, and it is not necessary to see those methods). Why has to be this way? This should be related to the life cycle of the entire page. But probably, when we call Form1.controls.Add () in Page_Load (), the parent control Form1 is in the Load phase (the sixth line above), which will call some of the way to pull the drop-down box to let it go through it-> loading The status, one of which is to call the parent class ListControl of TrackViewState, Dropdownlist behind INIT, Override TRACKVIEWSTATE, which calls the TRACKVIEWSTATE of the Items (ListItemcollection class) object. As a result, if you change the Items of the dynamic DROPDOWNLIST control after form1.controls.add (), those ListItem will be saved because the ListItemCollection object Override has saveViewState (). ListItem added before form1.controls.add () will not be saved. When this control, SELECTEDINDEX is grouped correctly (the selected value of the page retrace): system.web.ui.pageprivate void processRequestMain () base.loadrecurs (); // Call this.onload (Eventargs {This.processpostdata (this._leftoverpostdata, false);}

System.Web.ui.pageprivate void ProcessPostData (NameValueCollection PostData (String Text) Foreach

1 in

PostData) {Control Control1 = this.FindControl (Text1); ipostbackdatahandler handler1 = (iPostBackDataHandler) Control1; handler1.loadpostdata (text1, this._requestvaluecollection);}

转载请注明原文地址:https://www.9cbs.com/read-102860.html

New Post(0)