Dynamically create the Asp.net control and save its status, which is summarized as follows:
1: Background Knowledge: You need to know the lifecycle of the page.
2: method summary:
1>
In the declaration area of the page code file (the label control is used as an example here ):
Label x = new label ();
The code in the pageload event is:
Protected void page_load (Object sender, eventargs E)
{
This. Page. Controls. Add (X );
}
When the X value needs to be set on the page, write: X. Text = "Zzz"; and so on. In this way, no matter how the page is refreshed, You can dynamically create controls and save the status.
2>
Idea: dynamically Add a control to an existing control or control container on the page, and then set its status as needed.
For example:
<Asp: repeater id = "repeater1" runat = "server" onitemdatabound = "repeaterincluitemdatabound">
<Itemtemplate>
<Asp: literal id = "TR" runat = "server"> </ASP: literal>
</Itemtemplate>
</ASP: repeater>
Write :( E. Item. findcontrol ("ds") as literal). Text = "";
The two methods are similar: Once a control is added to the Control tree of the page, the trackviewstate () method tracks its status. This method is automatically triggered as long as the control is added to the Control tree.