views:

181

answers:

2

I am converting a web site project to a web application project in VS 2008 and i've run across a query regarding dynamically loading user controls.

<%@ Reference Control="~/UserControls/MyUserControl.ascx" %>

and then in the page I simply called...

Dim ucSupplierDetails As New ASP.usercontrols_myusercontrol_ascx

Sadly when updateing to a web applciation project, this is no longer a valid line. Is there an alternative?

+2  A: 

Try using <%@ Import namespace="Namespace.Of.Your.Usercontrol" %> instead

Jan Jongboom
+3  A: 

To dynamically load your user controls here is an alternative :

Dim ucSupplierDetails As New UserControl 
ucSupplierDetails.LoadControl("~/UserControls/MyUserControl.ascx")
placeholder.Controls.Add(ucSupplierDetails)

EDIT : Here is a second option, put your user controls into a namespace manually :

Namespace MyUserControlNamespace

    Public Class MyUserControl Inherits System.Web.UI.UserControl

    End Class

End Namespace

Don't forget to change your user control's class declaration (Inherits attribute at last line) :

<%@ Control Language="VB" AutoEventWireup="true" 
    CodeFile="MyUserControl.ascx.vb" 
    Inherits="MyUserControlNamespace.MyUserControl" %>

And now, you can access them by it's namespace :

Dim ucSupplierDetails As New MyUserControlNamespace.MyUserControl
Canavar