CodeFile vs CodeBehind page directive

Hey guys

I have been working and a website solution. Which I have recently upgraded to a Web Application. But now its changed all the page directives of codeFile to codeBehind, and wen I upload a file, it breaks untill I change the directive to CodeFile.

What are the differences between the 2 and which is the better one to use?

I have tried google, but couldnt find anything concrete.

Thanks for any feedback.

I prefer have two files per page - with ASPX template and with code. This simplifies intellisense (autocomplete) and separates presentation from logic (in some way).

A web application compiles all the .vb/.cs files into one dll most of the time and when you deploy you don’t need the .vb/.cs files just the .aspx/.ascx and .dll files (normally in the bin folder). This is similar to the way asp.net 1.1 websites worked by default in visual studio. You presumably got an error because you didn’t deploy the .dll in this case. The attribute codebehind effectively tells the compiler to look for a .dll within the website’s folder structure.

Previously your web site was using the default which does not compile the files into a .dll (well not in the same way) so you need to deploy the .vb/.cs files along with the .aspx/.ascx. When a site is opened for the first time on the server in this mode the .vb/.cs files are compiled into a .dll which is stored in the temporary internet files for that web site. When you make changes to these .vb/.cs files re-deploy and open the site they will be recompiled.

Changing the attribute back to codefile changes the site back to comiling using the second method.

Ahh perfect. Thanks a lot. That is exactally wat i thought. But wen i googled it 1 result said that codebehind does not support partial classes where as CodeFile does

Just a question. What is the benefits of using a Web Application other than convenience. Security is also not an issue as I have my own dedicated servers.

Plz help me understand this. As it seems like more sense to me to keep it website project so that i dnt have to upload 1mb+ dll every time I make a change.

Thanks for any feedback

Security tends to be the main issue in that the code files are on the server. The main reason web applications were brought in was to give experienced asp.net 1.1 developers a familiar kind of project setup. I’m happy enough to upload the code files as the only sensitive data would really be in the web.config anyway if you stored connection strings there and so on. I did alot of developing with 1.1 but had no problem moving on to the new model when version 2.0 arrived so I never really bothered with web apps.

There are some other good reasons (reflection comes to mind) to have things in one fix-named DLL with namespaces that you define. The biggest one is having a project file to manage things is handy if you do use some fancier build/deployment tricks.

But it really is six of one, half-dozen of the other. Personally I prefer the old, web application style model myself.

Oh, i see. Thanks for the replies. So far I prefer the website model.

Main reason is the server is still using that, and we are changing some files while building others, so at this point in time it actually seems not such a great idea updating after all.

Another reason is that we are 3 programmers and 2 designers working on 1 project on a local server. It is a bit of a mission to build every time I make a small change that doesnt require debugging.

The designers are using Dream weaver for their work, as they do not really like VS(Ive tried to sway them, but they use it some times, but say its to slow) and they will need to change a few things on the code behind page and now cnt see the changes untill he builds the project in VS.

I know you get programs for the server that auto build the project, but seems like a bit of an over kill with no real reason to move away from the website model

Thanks again for the replies

PS. I also dnt like having to upload a dll thats over 1mb on this dodgy internet of ours. lol

Another reason is that we are 3 programmers and 2 designers working on 1 project on a local server. It is a bit of a mission to build every time I make a small change that doesnt require debugging.

The designers are using Dream weaver for their work, as they do not really like VS(Ive tried to sway them, but they use it some times, but say its to slow) and they will need to change a few things on the code behind page and now cnt see the changes untill he builds the project in VS.

You really need subversion to keep everyone on the same page and then get all those coders building/designing/tweaking on their own machines.

+1

And a Continous Integration will ease the building/deployment story too. Any project with more than one person involved should really use a VCS + CI Server

Hi

Yes, we have subversion. Tortoise, and we develop on our own machines. Actually not at the moment as we having a problem with the server, but as soon as its sorted we will be using it again. But the thing his the designers still sometimes need to build it, which they cnt do as they mostly use dreamweaver.

Thanks guys