This documentation is archived and is not being maintained.

TemplateControl.LoadTemplate Method

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

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public ITemplate LoadTemplate (
	string virtualPath
)
public ITemplate LoadTemplate (
	String virtualPath
)
public function LoadTemplate (
	virtualPath : String
) : ITemplate
Not applicable.

Parameters

virtualPath

The virtual path to a user control file.

Return Value

An instance of the specified template.

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();
   }
}

void Page_Load(Object sender, System.EventArgs e)
{
    if (!(get_IsPostBack())) {
        DataList1.set_AlternatingItemTemplate(
             LoadTemplate("newtemplate.ascx"));
        DataList1.set_DataSource(CreateDataSource());
        DataList1.DataBind();
    }
}//Page_Load

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: