I have a web site(not web app) which has a default.aspx
and default.aspx.cs
.
And it has an App_Code
folder with class A
in it.
So default.aspx.cs
. Looks like:
namespace test1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
And class A
:
namespace test1
{
public class A
{
_Default mDefaultRef;
public pageLogicIndividual(_Default defaultRef)
{
mDefaultRef = defaultRef;
}
}
}
I can use A
in _Default
. eg. if I type test1.
, while working in class _Default
, the IntelliSense will show both classes.
But if I type test1.
, while working in class A
, the IntelliSense will only show A
.
Why can't I use _Default
in A
?
Error : the type or namespace name does not exist in the namespace (are you missing an assembly reference )
Edit:
I'll try to clarify.
While working in the .cs
file where class _Default
resides I can type test1.
, which is the namespace, and the intellisense will show me class _Default
and Class A
.
But if I'm working in the .cs
file where class A
resides and type test1.
, which is the namespace, then the intellisense will only show me class A
.
I have had this challenge in the past.
Open up the App_Code folder node in Visual studio. Right click on the concerned class, then click properties
In the properties pane, change Build Action to Compile.
It should work fine now.
Your problem is with your misleading namespace
that you've added yourself after the new file has been created because ASP.NET Web Sites do not have namespace. The namespaces are available in Web Applications projects. i.e. after a new WebSite is created, namespace doesn't added to the files.
So you don't need to place your class A
inside the test1
namespace because you can use A
in default.aspx.cs
even without namespace but you can not access other WebForm page classes from a Webform page or App_Code
classes.
BTW if you want to use the necessary and reusable methods within a class of the Default
Web Form, you can move those methods out to A
class which is under App_Code
and as I said already you can use it within all the Web Form CodeFiles
without providing namespace for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With