473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is it a good idea to put all code-behind in App_Code folder?

Hi, when I add a new page in my asp.net 2 project and put some controls
there, everything works fine until I move the code behind into App_Code
folder.--When I compile , it tells me that control "not exist in the current
context".

I thought putting code behind in App_Code folder is the recommendation for
asp.net 2. In order to do so, I just simply remove the codefile attribute in
@page.

Maybe my perception of putting all code in App_Code folder is totally wrong
from the beginning.Can you help me on this question?

Thanks a lot.
Mar 2 '06 #1
2 3186
You should *not* put *any* page code-behind files in the app_code folder.

The app_code folder is for class source files, not for page code-behind files.

Get the gist of the coding models,both for 1.1 and 2.0, here :
http://msdn.microsoft.com/library/de.../internals.asp

There's additional background information at :
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"walter" <ww*@morneausobeco.com> wrote in message
news:86**********************************@microsof t.com...
Hi, when I add a new page in my asp.net 2 project and put some controls
there, everything works fine until I move the code behind into App_Code
folder.--When I compile , it tells me that control "not exist in the current
context".

I thought putting code behind in App_Code folder is the recommendation for
asp.net 2. In order to do so, I just simply remove the codefile attribute in
@page.

Maybe my perception of putting all code in App_Code folder is totally wrong
from the beginning.Can you help me on this question?

Thanks a lot.

Mar 2 '06 #2
Hi,

I wouldn't say it's a recommendation to place everything to App_Code.
Code-behind files are code-behind files and they serve mostly best as such
as separate files, unless you create some sort of base class for your
code-behind classes (such class would be a good example to place to
App_Code). I'd see App_Code a good place for helper classes etc when you
need component-like functionality & look and feel in presentation layer. And
it's handy because of the dynamic build.

You'd see the error because partial class feature works only with codefile
attribute e.g that separate companion class is created for the code-behind
class behind the scenes and this companion class contains the member
declarations which you don't have to put yourself in code-behind class.
These two are merged when compiled and the merged class is used as base
class for the class generated for aspx page.

If you don't use codefile attribute, you'd need to create the member for the
controls manually into the code-behind class.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"walter" <ww*@morneausobeco.com> wrote in message
news:86**********************************@microsof t.com...
Hi, when I add a new page in my asp.net 2 project and put some controls
there, everything works fine until I move the code behind into App_Code
folder.--When I compile , it tells me that control "not exist in the
current
context".

I thought putting code behind in App_Code folder is the recommendation for
asp.net 2. In order to do so, I just simply remove the codefile attribute
in
@page.

Maybe my perception of putting all code in App_Code folder is totally
wrong
from the beginning.Can you help me on this question?

Thanks a lot.

Mar 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Generic Usenet Account | last post by:
I am going through some legacy code that has an "isNull()" method defined on certain classes. I can see that this can be a good way to eliminate certain types of crashes, by making this the first...
19
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the...
14
by: dreamcatcher | last post by:
I always have this idea that typedef a data type especially a structure is very convenient in coding, but my teacher insisted that I should use the full struct declaration and no further...
8
by: markus | last post by:
Hi, As I been programming in C I have discovered more and more tools that really helps to speed up the development process when writing programs. Examples of such tools are cscope, cbrowser,...
43
by: Sensei | last post by:
Hi! I'm thinking about a good programming style, pros and cons of some topics. Of course, this has nothing to do with indentation... Students are now java-dependent (too bad) and I need some...
59
by: Alan Silver | last post by:
Hello, This is NOT a troll, it's a genuine question. Please read right through to see why. I have been using Vusual Basic and Classic ASP for some years, and have now started looking at...
150
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
54
by: sam.s.kong | last post by:
Hi! I've been programming ASP for 5 years and am now learning PHP. In ASP, you can use GetRows function which returns 2 by 2 array of Recordset. Actually, it's a recommended way in ASP when you...
5
by: mike3 | last post by:
Hi. Is this a good idea?: <begin code> /* Addition operator: += */ const BigFix &BigFix::operator+=(const BigFix &rhs) { ErrorType err; int lhs_sign = sign, rhs_sign = rhs.sign;
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.