Use LoadControl to add user defined control (VB.net)
<%@ Page Language=VB Debug=true %>
<%@ Register
TagPrefix="My"
TagName="SimpleControl"
Src="UserControlControls.ascx"
%>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
Dim MyControl as UserControl = _
LoadControl("UserControlControls.ascx")
MyForm.Controls.Add(MyControl)
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Implementing a User Control on an ASP.NET Page</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form
runat="server"
id="MyForm"
>
<My:SimpleControl
id="MSC1"
runat="server"
/>
</form>
</BODY>
</HTML>
<%--UserControlControls.ascx
<Table style="font: 10pt verdana;border-width:1;
border-style:solid;border-color:black;" cellspacing="15">
<TR>
<TD>
<asp:Label
id="lbl1"
runat="server"
Font-Bold="True"
Text="User Name: "
/>
</TD>
<TD>
<asp:TextBox
id="txtUserName"
runat=server
/>
</TD>
</TR>
<TR>
<TD>
<asp:Label
id="lbl2"
runat="server"
Font-Bold="True"
Text="Password: "
/>
</TD>
<TD>
<asp:TextBox
id="txtPassword"
runat=server
TextMode="Password"
/>
</TD>
</TR>
</Table>
--%>
Related examples in the same category