Using the Reference Directive
When you load a User control with the Page.LoadControl()
method, the User control is returned as an instance of the System.Web.UI.Control
class. This means that if the User control includes any custom properties, the properties aren’t available when you dynamically load the User control.
If you dynamically load a User control, you need to cast the control to the correct type before you can access any of the control’s custom properties. To get a reference to a User control’s type, you must use the <%@ Reference %>
directive.
For example, imagine that you need to create a form that displays different questions depending on the answers that a user provides for previous questions. In that case, you can dynamically load ...
Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.