User Control cannot be accessed by another CS file
There is a UserControlA
which was already developed when I joined on a project. It is in a Project which I will call MyProjectWeb
and it's namespace is MyProjectWeb.Common
.
namespace MyProjectWeb.Common
{
public partial class UserControlA : System.Web.UI.UserControl
{
...
There is another WorkFlowManager project that contains a class file which accesses this UserControl1.
MyProjectWeb.Common.UserControlA myUserControlA = (MyProjectWeb.Common.UserControlA)WizardControl.FindControl("TabContainer5$tpSomething$UserControlID");
Note: WorkFlowManager and MyProjectWeb are in the same solution.
开发者_JAVA百科This works completely fine. And now I want to create another UserControl which is UserControlB.
I followed the exact same thing.
namespace MyProjectWeb.Common
{
public partial class UserControlB : System.Web.UI.UserControl
{
But to my surprise, I cannot create an instance of UserControlB in the same code file in WorkFlowManager. MyProjectWeb.Common namespace does not even contain a UserControlB. When I compile I get obviously get a
The type or namespace name 'UserControlB' does not exist in the namespace 'MyProjectWeb.Common' (are you missing an assembly reference?)
Why is that I can reference UserControlA but not UserControlB which are in the same namespace from the WorkFlowManager cs file? If I access the MyProjectWeb.Common namespace anywhere inside the MyProjectWeb, I can see both the user controls. Anywhere to look for errors?
I am using Visual Studio 2005 with ASP .NET 2.0
It would depend upon how WorkFlowManager project references MyProjectWeb dll. If both projects are in same solution, then it should have been a project reference but you need to verify it. If the reference is made to dll file then you need to see where exactly the referenced file is stored - my guess is that WorkFlowManager project is referencing a private copy of MyProjectWeb dll that obviously does not get updated when you rebuild MyProjectWeb.
I'd have to look at the project to know for sure, what you're saying above doesn't tell me quite enough.
Quick ideas:
- Make sure that UserControlB.cs is actually in the right project.
- Make sure that UserControlB.cs is marked as "Compile" for the build type.
- Make sure that UserControlB is actually "B" not "A" because, since they're partial, a spelling error could cause them to combine together.
- Those user controls are "partial" did you also copy the other part?
- Make sure the web project doesn't have any errors, it's possible that the project isn't being built correctly and the error you're getting is because of a stale assembly.
- Clean + Rebuild. Delete bin and obj directories manually.
精彩评论