Dynamic use of UserControl

D

DougS

I have a ASP.Net 1.1 application where I have several usercontrols, one is
called DetailLine, that I add to a panel dynamically. I am converting the
app to ASP.Net 2.0 and I cant do this anymore. LineType1 inherits from
DetailLine which inherits from UserControl.

1 Dim ucLine As DetailLine ' this line bombs

2 ucLine = CType(Page.LoadControl("..\UserControls\LineType1.ascx"),
DetailLine)

3 pnlDemoLines.Controls.Add(ucLine)


I cant understand why line one bombs in 2.0, why cant i see any of the
classes I created in my Inellisense? Here's the code behind the DetailLine
class:

Partial Class UserControls_DetailLine

Inherits System.Web.UI.UserControl

Private iInvoiceNumber As Integer

Public ReadOnly Property InvoiceNumber() As Integer 'example property

Get

Return iInvoiceNumber

End Get

End Property

End Class

Thanks in advance, DougS
 
G

Guest

DougS,

As per the code below - the actual control type is now
UserControls_DetailLine - hence DetailLine is not a valid type
 
D

DougS

Yes, I've tried that Sergey. It still doesnt work. I tried creating another
class and inherit from the UserControls_DetailLine class:

Base class:

Partial Public Class UserControls_DetailLine
Inherits System.Web.UI.UserControl

Private iInvoiceNumber As Integer
Public ReadOnly Property InvoiceNumber() As Integer
Get
Return iInvoiceNumber
End Get
End Property
End Class

Inherited class:

Partial Class UserControls_LineType1
Inherits UserControls_DetailLine ' THIS LINE WONT COMPILE
Public Property Test1' rest of code
End Property
End Class
 
G

Guest

DougS,

I suspect that you are using ASP.Net default website setup - file project
(as opposed to web project), and your UserControls folder is not under
App_Code - then it will not be visible to other objects within your website.
The ASP model have changed quite a bit from 1.1 to 2.0 and it took me some
time to get used to new model.

My suggestion would be to try utilizing VS upgade wizard to see what sort of
objects VS creates. Also do not forget to backup your 1.1 before - though
provides backup as an option during conversion, I usually prefer to know
exactly where things are.

Then you will notice that VS puts classes for your user controls inside
App_Code folder, and then the implementations inside UserControls folder will
inherit those. This way your controls are visible across the site and your
site structure is preserved (sort of).

Please let me know if what I wrote made sense
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top