TemplateControl.LoadTemplate(String) Method

Definition

Obtains an instance of the ITemplate interface from an external file.

public System.Web.UI.ITemplate LoadTemplate (string virtualPath);

Parameters

virtualPath
String

The virtual path to a user control file.

Returns

An instance of the specified template.

Examples

The following code example demonstrates how to use the LoadTemplate method to add a user control as an alternating item to a DataList Web server control named DataList1. The user control implements the ITemplate interface and is contained in a file named Newtemplate.ascx.

void Page_Load(Object sender, EventArgs e) 
{
   if (!IsPostBack) 
   {  
      DataList1.AlternatingItemTemplate = LoadTemplate("newtemplate.ascx");
      DataList1.DataSource = CreateDataSource();
      DataList1.DataBind();
   }
}

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also