Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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
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)
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!
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.