Results 1 to 8 of 8

Thread: Dynamically loading WebUserControl

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Dynamically loading WebUserControl

    Hi there,

    im having an issue dynamically loading a webusercontrol.

    In my vs2008 solution i have several projects. their is the main web project, then several other projects that are controls to be used in the main project.

    In the main web application when a user requests a page it will dynamically load a WebUserControl in on of these other projects, based on a supplied Id in the querystring.

    I publish each project that has a webusercontrol to a directory called controls under the main project.
    ie:
    c:\inetpub\wwwroot\MyWebProject
    c:\inetpub\wwwroot\MyWebProject\Controls

    so when i try and load a web control to my default aspx page i do the following

    Dim defaultCtrl As Control = LoadControl("~/Controls/DefaultWebControl/newPage.ascx")
    me.Controls.Add(defaultCtrl)

    however i keep gettin an exception saying "Could not load type XXXXXX"
    and the exception is of httpparser.

    this is very frustrating, i cant see why this doesnt load.
    if i try load the webusercontrol into a aspx page in the same project it will load. But it will not load for my main project..

    Thanks for any help
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Dynamically loading WebUserControl

    did you import the control into the other projects?
    Last edited by Besoup; Nov 25th, 2008 at 06:30 AM.

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Dynamically loading WebUserControl

    the exeption occurs on the LoadControl line.

    my web control is going to have all my html, im loading the control into a empty aspx.

    cheers
    Last edited by Strider; Nov 25th, 2008 at 06:31 AM.
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  4. #4
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Dynamically loading WebUserControl

    yeah I just re-read and edited my original post... it's too early here. :P

  5. #5

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Dynamically loading WebUserControl

    haha no worries....

    what do u mean by import? How do i import the control into my main project?
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  6. #6

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Dynamically loading WebUserControl

    Well i found the issues was the i need to add a reference to the main project to the project that contains the web controls.

    I was hoping that i wouldnt need to this as i this means i will have to rebuild and publish the main project anytime i need to add a new control...

    does anyone know of anyway around this...
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  7. #7
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Dynamically loading WebUserControl

    I don't think... there is a way around the build problems and potential unforseen runtime bugs. I have often wanted to break apart a large website into different projects but it's just been too problematic.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Dynamically loading WebUserControl

    Of course the ASCX needs to be in the same project as the web application. The entire context of an ASCX is that it is a web user control for the project in which it exists. If the control sits outside the web project, it needs to be a server control, because the only reason you're make it an external web user control is if it was meant to be reused across web projects.

    Is there a way around it? Yes, in crude but epic proportions. It'd involve you using reflection. Or, you could just have a look at DotNetNuke's code to see how they do it. People write frameworks for this kind of stuff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width