Writing all code in code-behind is ugly thing. Massive code in single file(in a page) will make things harder. Tough to debug.
Seperate classes for some code(like DB related, generic) is for code reusability, maintainability. And easy for debugging. While migration this way is easy, because you have seperated things in seperate classes/layers so you'll have to develop only UI related things.
Here a sample article
Creating ASP.NET Applications with N-Tier Architecture[
^]
And also take a look at
MVC[
^]