This documentation is archived and is not being maintained.

TemplateControl.LoadTemplate Method

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

[Visual Basic]
Public Function LoadTemplate( _
   ByVal virtualPath As String _
) As ITemplate
public ITemplate LoadTemplate(
 string virtualPath
public: ITemplate* LoadTemplate(
 String* virtualPath
public function LoadTemplate(
   virtualPath : String
) : ITemplate;


The virtual path to a user control file.

Return Value

An instance of the specified template.


[Visual Basic, C#] The following example uses 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.

[Visual Basic] 
Sub Page_Load(sender As [Object], e As EventArgs)
   If Not IsPostBack Then
      DataList1.AlternatingItemTemplate = LoadTemplate("newtemplate.ascx")
      DataList1.DataSource = CreateDataSource()
   End If
End Sub 'Page_Load

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

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

TemplateControl Class | TemplateControl Members | System.Web.UI Namespace