About dynamically building controls and dynamically acquiring handle values for controls

Source: Internet
Author: User
Tags contains
Dynamic | Control from the issue of the post: Help me inside the need to dynamically get the handle value of the control, these days in the Vs.net tried, summed up a little experience, as follows:
1. Dynamically generating controls:
Either in asp.net or in Windows application, each control can be used as a parent control, where some child controls are added, and of course add can be added manually, while dynamically adding controls are generally as follows: (asp.net)
Dim textbox As TextBox ' dynamically adding a TextBox control
Textbox=new textbox ()
Textbox.id= "Test" specifies some properties of this textbox
textbox.text= "Fun"
Me.Controls.Add (textbox) ' Dynamically add this textbox on the current window
In vs.net. Each control has a controls property, which returns a collection of child controls it contains, you can use the Add method to dynamically add a control, the clear method empties all controls, and so on
2. Dynamically obtain the handle value of the control (also in asp.net)
If you want to get the handle value of a control's child control, simply return one from its controls collection, assuming that only our dynamically generated textbox in the previous example is a control
Then: Dim textbox As TextBox
Textbox=me.controls (0) ' Gets the handle value, if there are multiple, then the Me.Controls (1), Me.Controls (2) and so on are available
Response.Write (Textbox.id ()) ' its property value
Response.Write (TextBox.Text ())
And if you want to get the handle value of its parent control (that is, the control that contains it)
Just do this: Textbox.parent is the handle value of the current window
You can also traverse all child controls under one control
For I=0 to Me.controls.count-1
Response.Write (Me.Controls (i). ID)
Next

In the Windows application like controls's various properties are also able to use, and uses in the ASP.net consistent, only in Beta2 version cannot bounce out this attribute, does not know why, perhaps this is the Beta2 compiler's small bug bar!
Summary: Using dynamic methods to obtain and generate controls gives the program a lot of flexibility! It is mainly using the control of the controls set of some methods!
These are my own groping out of the deficiencies of the place also please advise!

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.