Control in the actual development, it is often necessary to download some of the service controls or user controls based on the actual need for motion, which is generally divided into two kinds of meditation and motion. Here's how to load the controls, Dynamic loading in the leaves the control is commonly used as a container to load these dynamic placeholder controls. This example is the point "Btnaddcontrol" to add a new control
Sub Btnaddcontrol_click (Sender as object,e as EventArgs)
Dim Txtbox as TextBox = New textbox
' First clear all control in placeholder and add the resulting textbox control to the placeholder control
PlaceHolder1.Controls.Clear ()
PLACEHOLDER1.CONTROLS.ADD (txtbox) ' This basically has a TextBox control, when the "Btnaddcontrol" can see a textbox!
It is also possible to define the various attributes of the loaded textbox (note that you first add the control and then set its attributes)
Txtbox.id= "MyTextBox"
Txtbox.backcolor=system.drawing.color.lightgreen
Txtbox.text= "This is a textbox!"
ViewState ("Txtboxcontrol") =true
End Sub
This will load a TextBox control at the click of the button, but there's a problem: it's when you refresh the leaf that the textbox doesn't see it again. This is because the control of the motion is not going to save his viewstate state on the leaf surface, you can't think of a problem Must be in the Page_Load () event, as follows:
Sub Page_Load (Sender as object,e as Eventargs)
' To determine if there is a viewstate of a previously generated control in ViewState, it is possible to regenerate the control and to download its previous ViewState state automatically
If ViewState ("Txtboxcontrol") <> nothing Then
Dim Txtbox as Textbox=new textbox
PLACEHOLDER1.CONTROLS.ADD (Txtbox)
Txtbox.id= "MyTextBox"
End If
End Sub
It's a way to move the user control (PLACEHOLDER1.CONTROLS.ADD ("Header.ascx")
------------------------------------------------------------------------
The first time I wrote an article, it was a bit messy.