
266
|
Chapter 12: The Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Parameter
Boolean
A Boolean value that indicates whether the page contains child controls.
Example
The code example displays a message indicating whether the page has controls in
its Controls collection, based on the value returned by HasControls:
Sub Page_Load( )
If Page.HasControls = True Then
Message.Text = "The page contains controls."
Else
Message.Text = "The page does not contain controls."
End If
End Sub
LoadControl
ObjControl = Page.LoadControl(StrPath)
Returns an instance of the user control defined in the strPath user control file.
This allows dynamic loading of user controls instead of using the
@ Register
directive.
Parameters
objControl
An object of type Control that represents the user control specified in the
given path.
strPath
The virtual path to a user control file.
Example
The example uses the LoadControl to load a user control at runtime and adds it to
the page’s Controls collection:
Sub Page_Load( )
Dim Hello As UserControl = LoadControl("hello.ascx")
Page.Controls.Add(Hello)
End Sub
The user control hello.ascx is as follows:
<h1>Hello, World!</h1>
MapPath
String = Page.MapPath(virtualPath)
Returns the physical path that corresponds to a given virtual path.
Parameters
String
A String containing the physical path that corresponds to
virtualPath.