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.
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.