Instead of declaring your UserControl as a “Control” type, declare it as the class name specified in the UserControl.ascx file:
<%@ Control className="MyUserControl" %>
So, in the code on the .aspx page:
Dim objControl as ASP.MyUserControl = CType(LoadControl("~\Controls\MyUserControl.ascx"), ASP.MyUserControl)
Additional information is available on MSDN .
EDIT: , . , , , .
.aspx.vb "ASP.ContentModule" "Namespace.ClassName" .ascx.vb. , , Add .
#, vb, . "".
ASCX:
namespace Tester.modules
{
public partial class content : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
ASPX:
namespace Tester
{
public partial class _Default : System.Web.UI.Page
{
private Namespace.ClassName loadmodule;
protected void Page_Load(object sender, EventArgs e)
{
loadmodule = (Namespace.ClassName)LoadControl("~/modules/content.ascx");
Modulecontainer.Controls.Add(loadmodule);
}
}
}