To add controls to the surface in motion

Source: Internet
Author: User
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.