Click here to Skip to main content
15,748,049 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I decided to post on this site as it seems to be the friendliest and most down to earth of all the forums. I wonder if anyone can help me - I spent all yesterday searching for the answer to no avail!

I have nearly finished a VS2010 Website Project using and c#. I have no problem at all seeing classes/methods/fields defined in app_code/whatever.cs pages from my aspx.cs pages but if I define a class in the aspx.cs page, I can't see it from the app_code/whatever.cs page. I've messed about with namespaces, usings and made sure everything is as public as possible and have proven that the same class put in another .cs page in app_code can be seen by app_code/whatever.cs - it's only when put the class into the aspx.cs area that intellisense can't see it. (I'm getting "The type or namespace name 'xxxxx' could not be found (are you missing a using directive or assembly reference)). The aspx.cs page sits underneath the .aspx file in solution explorer. I tried moving the whatever.cs file from the app_code folder to root and that didn't help.

The closest I have found to an answer on the internet is that I should have created a Web Application instead of a Website and then I would be able to see the classes between aspx.cs and .cs pages in both directions.

So, before I start posting any code, could anyone tell me if this last point is true? Apologies if this is really obvious to everyone - maybe I have misunderstood the way data is allowed to flow in a website project - I'm new to all of this so there may be fundamental gaps in my knowledge.....but I've managed to build 99% of it so just need help with the remaining 1%!

If you guys feel however that I should be able to expose aspx.cs page classes to the app_code/ classes in a website project then I will post code and explain in more detail why I'm trying to do this.

To avoid being shouted at with "this question has been answered before", can I just clarify that there are loads of posts where people can't see classes defined in app_code from the code behind page ..... my problem is the other way round, I really have looked everywhere!

Many thanks

Updated 13-Oct-10 1:51am

1 solution

You will not be able to access class of aspx.cs page inside app_code folder unless you put it under App_Code folder. There may be a workaround to avoid moving the aspx.cs by using BaseClass. You can find the details here.

And yes, if you use "web application" you can access aspx.cs class inside app_code folder without any issue.
Share this answer
pierreluigi88 13-Oct-10 9:10am    
Hi Saini, thanks for the quick response - I'm glad you've confirmed that this will work when it's a web app - I'll get converting now!
saini arun 14-Oct-10 1:46am    
My pleasure. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900