Error when Load control dynamically with LoadControl

Discussion in 'ASP .Net Building Controls' started by Stephane, Mar 30, 2008.

  1. Stephane

    Stephane Guest

    Hi,

    I have created a user control (ASP.NET 2.0) in the folder "mining" of my
    project. There's no namespace by default, but other aspx pages are in the
    namespace iMinr.mining.

    The declaration of this user control goes like this :

    public partial class mining_ucPubDetails : System.Web.UI.UserControl

    And in the ASCX page, this is the control declaration

    <%@ Control Language="C#" AutoEventWireup="true"
    CodeFile="ucPubDetails.ascx.cs" Inherits="mining_ucPubDetails" %>

    Now, in a C# page in the iMinr.mining namespace where it's specified :

    using iMinr.mining;

    I try to load dynamically the control:

    mining_ucPubDetails pub =
    (mining_ucPubDetails)LoadControl("ucPubDetails.ascx");

    And if I compile, I got this :

    The type or namespace name could not be found

    The weird thing is that it works on my dev server despite this error. But on
    production, I doesn't.

    Why the project can't find the control class? How can I load a user control
    dynamically?

    Thanks

    Stephane
    Stephane, Mar 30, 2008
    #1
    1. Advertising

  2. Stephane

    Stephane Guest

    Solved.

    I added this to the aspx page where I use the control:

    <%@ Register Src="ucPubDetails.ascx" TagName="ucPubDetails" TagPrefix="uc" %>
    <%@ Reference VirtualPath="~/mining/ucPubDetails.ascx" %>

    Steph

    "Stephane" wrote:

    > Hi,
    >
    > I have created a user control (ASP.NET 2.0) in the folder "mining" of my
    > project. There's no namespace by default, but other aspx pages are in the
    > namespace iMinr.mining.
    >
    > The declaration of this user control goes like this :
    >
    > public partial class mining_ucPubDetails : System.Web.UI.UserControl
    >
    > And in the ASCX page, this is the control declaration
    >
    > <%@ Control Language="C#" AutoEventWireup="true"
    > CodeFile="ucPubDetails.ascx.cs" Inherits="mining_ucPubDetails" %>
    >
    > Now, in a C# page in the iMinr.mining namespace where it's specified :
    >
    > using iMinr.mining;
    >
    > I try to load dynamically the control:
    >
    > mining_ucPubDetails pub =
    > (mining_ucPubDetails)LoadControl("ucPubDetails.ascx");
    >
    > And if I compile, I got this :
    >
    > The type or namespace name could not be found
    >
    > The weird thing is that it works on my dev server despite this error. But on
    > production, I doesn't.
    >
    > Why the project can't find the control class? How can I load a user control
    > dynamically?
    >
    > Thanks
    >
    > Stephane
    >
    Stephane, Mar 30, 2008
    #2
    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. huobazi
    Replies:
    1
    Views:
    662
    David Waz...
    Jul 3, 2003
  2. Jeremy
    Replies:
    2
    Views:
    5,742
    Jeremy
    Jun 24, 2004
  3. =?Utf-8?B?UmV6YSBOYWJp?=

    Load User Control Dynamically, Cast object dynamically

    =?Utf-8?B?UmV6YSBOYWJp?=, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,690
    Matt Berther
    Mar 5, 2005
  4. =?Utf-8?B?UmV6YSBOYWJp?=

    Load User Control Dynamically, Cast object dynamically

    =?Utf-8?B?UmV6YSBOYWJp?=, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,331
    Scott Allen
    Mar 4, 2005
  5. Rory Plaire

    When does LoadControl really load the control?

    Rory Plaire, Aug 12, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    148
    Rory Plaire
    Aug 12, 2003
Loading...

Share This Page