asp.net.ph

Skip Navigation Links

@ Reference

ASP.NET Syntax   ASP.NET Page Syntax   Page Directives


Declaratively indicates that another user control or page source file should be dynamically compiled and linked against the page in which this directive is declared.

<%@ Reference page | control = "pathtofile" %>

Attributes


Page Web Form that ASP.NET should dynamically compile and link the current page against at runtime.
Control User control that ASP.NET should dynamically compile and link the current page against at runtime.

Remarks

Using this directive allows you to dynamically compile a page or user control and add it to the ControlCollection object, accessed through the Controls property, for the page or server control. This allows you to cast the returned type after you have called the LoadControl method ( inherited by the page from the TemplateControl class ).

Syntax Example

The below code snippet demonstrates using this directive to link a user control, MyControl.ascx, and load it to a containing page using the LoadControl method. When it is loaded to the page, the user control’s MyProperty value is set, and the user control is added to a PlaceHolder server control’s ControlCollection object through the Controls property.

<%@ Reference Control = "MyControl.ascx" %>

<script language="C#" runat=server>
void Page_Load ( Object sender, EventArgs e ) {
   MyControl myControl = ( MyControl )
      Page.LoadControl ( "MyControl.ascx" );
   myControl.MyProperty = "Color";
   PlaceHolder.Controls.Add ( myControl );
}
</script>

<html>
<body>
   <asp:placeholder id="PlaceHolder" runat=server />

</body>
</html>
  C# VB

See Also

Web Forms User Controls   Introduction to Web Forms



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note