For my project(in asp.net) i wrote near 1000 lines of c# code for one asp.net page.It includes so many functions.The problem is,it is going complicated while i am writing more codes on one page.How can i make multiple c# files for one asp.net page?? I tried by adding new class in VS2008.But calling a function from one file to other is making error(item is not present in current file).How can i do that??
6 Answers
Partial classes will allow you to split your large class over many files. However, I would suggest that is not the ideal solution.
You could create other classes that your page uses to perform a lot of its functionality.
You could move some of the functionality into UserControls.
You could move some shared functionality into a master page and then have multiple pages to perform individual tasks.
Comments
While I see why everyone is suggesting using partial classes, they only provide physical separation of code in separate files. I think your problem here is not the separation of the code itself, but rather splitting your functionality in components.
If there's functionality in a page that is logically grouped together, why not extract it in an ASP.NET control, expose events in this control and have the code + functionality grouped logically? This would add a bit of more effort required, but would be much, much cleaner and easily maintained. Also, if you decide to reuse some part of the page, it would be copy-paste hell if the functionality is contained as code in a page and not a control.