Cannot find type of user control?

J

Jacob Avlund

Hello all,

I wish to load two user controls (cart.ascx and products.ascx)
programatically.

What I'm doing right now:

In my aspx file, two references are added:

<%@ Reference Control="./products.ascx" %>
<%@ Reference Control="./cart.ascx" %>

In the ascx files, I have added a corresponding classname:

<%@ Control Language="C#" classname="Products" src="duplicate.ascx.cs"
Inherits="Duplicate.Products" %>
<%@ Control Language="C#" classname="Cart" src="duplicate.ascx.cs"
Inherits="Duplicate.Cart" %>

Here comes the problem now. I've put this code in my aspx.cs file:

Control productsControl = LoadControl( "./products.ascx" );
Control cartControl = LoadControl( "./cart.ascx" );
if( productsControl != null )
( (Products)productsControl ).listPurchases += new
ListPurchasesEventHandler( ( (Cart)cartControl ).listPurchases );
Page.Controls.Add( productsControl );
Page.Controls.Add( cartControl );

It simply refuses to cast to (Products) and (Cart) at line 4. The problem
being that the compiler apparently does not know the type.

I've tried for days to get it working. All files are in the root directory
and the same namespace. If I compile the ascx files to a dll file, it
apparently works - but I see no apparent reason why it shouldn't work the
other way?

Please help... all suggestions are very welcome.

Best regards and thanks in advance,

J.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top