This documentation is archived and is not being maintained.
TemplateControl.LoadTemplate Method
.NET Framework 1.1
Obtains an instance of the ITemplate interface from an external file.
[Visual Basic] Public Function LoadTemplate( _ ByVal virtualPath As String _ ) As ITemplate [C#] public ITemplate LoadTemplate( string virtualPath ); [C++] public: ITemplate* LoadTemplate( String* virtualPath ); [JScript] public function LoadTemplate( virtualPath : String ) : ITemplate;
Parameters
- virtualPath
- The virtual path to a user control file.
Return Value
An instance of the specified template.
Example
[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() DataList1.DataBind() End If End Sub 'Page_Load [C#] void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { DataList1.AlternatingItemTemplate = LoadTemplate("newtemplate.ascx"); DataList1.DataSource = CreateDataSource(); DataList1.DataBind(); } }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
TemplateControl Class | TemplateControl Members | System.Web.UI Namespace
Show: