|
-
Nov 25th, 2008, 05:59 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 25th, 2008, 06:22 AM
#2
Frenzied Member
Re: Dynamically loading WebUserControl
did you import the control into the other projects?
Last edited by Besoup; Nov 25th, 2008 at 06:30 AM.
-
Nov 25th, 2008, 06:27 AM
#3
Thread Starter
Fanatic Member
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
-
Nov 25th, 2008, 06:31 AM
#4
Frenzied Member
Re: Dynamically loading WebUserControl
yeah I just re-read and edited my original post... it's too early here. :P
-
Nov 25th, 2008, 06:34 AM
#5
Thread Starter
Fanatic Member
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
-
Nov 25th, 2008, 07:19 PM
#6
Thread Starter
Fanatic Member
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
-
Nov 26th, 2008, 12:44 AM
#7
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.
-
Nov 26th, 2008, 03:54 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|