I'm having exactly the same issue, and I can't find any reasonable workaround.
I?m now on my 3rd day of trying to get dynamic child UserControls to load in an ASP.NET 2.0 project. I'm perfectly desperate.
For help and a reasonable explanation, I'm willing to do nearly anything.
Here's the issue, takes me about 2 mins to reproduce:
- I have a terribly simple project called Master that is a web project.
- I have a subproject in a subfolder of Master called "subproject"
- The subproject has a control named "ChildControl.ascx"
In the master project's single page (Default) I have this code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UserControl uc = (UserControl)LoadControl("subproject/ChildControl.ascx");
}
}
In the subproject's ChildControl.ascx I have this code:
public partial class ChildControl : System.Web.UI.UserControl {
protected void Page_Load(object sender, EventArgs e)
{
string x = SharedCode.SayHello();
}
}
In the subproject I also have a class with a single static method called SayHello(). This class is in the App_Code folder of subproject.
When I run this project, I get this error:
Compiler Error Message: CS0103: The name 'SharedCode' does not exist in the current context
But of course it DOES EXIST.
I can't believe that this isn't possible. All I want to do is to use code IN THE SAME PROJECT with a static method.