By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,534 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,534 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.