
262
|
Chapter 12: The Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
</form>
</body>
</html>
Notes
For the ViewStateUserKey field to be effective, the EnableViewStateMac property
for the page must be set to
True, which is the default.
Collections Reference
Controls
ControlCollection = Page.Controls
Provides access to the ControlCollection instance associated with the page, with
which you can add or manipulate controls at runtime.
Parameter
ControlCollection
An object of type ControlCollection containing the controls associated with
the page.
Example
The code example uses the Controls property to display the Count property of the
ControlCollection class instance associated with the page. It then adds a new
Label control to the collection and displays the updated Count property by using
the new label.
Sub Page_Load( )
Message.Text = "There are currently " & Controls.Count & _
" controls on the page.<br/>"
Dim Message2 As New Label
Controls.AddAt(Controls.Count - 1, Message2)
Message2.Text = "There are now " & Controls.Count & _
" controls on the page."
End Sub
Notes
As with the Session and Trace properties, while you can retrieve a local reference
to the Controls collection associated with the page, it is more common to access
this instance directly through the Controls property, as shown in the example.
Note that when adding a control ...