Cannot find type of user control?

Discussion in 'ASP .Net' started by Jacob Avlund, Sep 23, 2004.

  1. Jacob Avlund

    Jacob Avlund Guest

    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.
     
    Jacob Avlund, Sep 23, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daves
    Replies:
    5
    Views:
    4,289
    topherzee
    Sep 10, 2008
  2. Samy
    Replies:
    4
    Views:
    576
  3. Samy
    Replies:
    2
    Views:
    2,005
  4. =?Utf-8?B?RQ==?=
    Replies:
    0
    Views:
    440
    =?Utf-8?B?RQ==?=
    Sep 11, 2007
  5. Davids

    cannot find the user control with it's ID

    Davids, Dec 26, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    157
    Ben Strackany
    Dec 27, 2004
Loading...

Share This Page