Creating multiple c # files for one asp.net page

For my project (in asp.net), I wrote about 1000 lines of C # code for one asp.net page. It includes so many features. The problem is that it gets complicated when I write more codes on one page. How can I make multiple C # files for one asp.net page? I tried to add a new class in VS2008. But calling a function from one file to another causes an error (the element is not in the current file). How can i do this?

+3
source share
6 answers

Partial classes allow you to split a large class into many files. However, I would suggest that this is not an ideal solution.

  • , , .

  • UserControls.

  • .

+2

.

+2

partial class, , , , codebehind (.aspx.cs) (. cs).

- , .

+1

.

0

, .

..

Newclass.cs
  namespace myapp.functions
  {
  // .
  }

Page.aspx.cs
   myapp.functions;
  //

0

, , . , , .

If there is functionality on a page logically grouped together, why not extract it in an ASP.NET control, set events in that control, and logically group the + code functionality? This would add a little more effort, but would be much, much cleaner and easier to maintain. In addition, if you decide to reuse some part of the page, it will be an addon for copying if the functionality is contained as code on the page, rather than a control.

0
source

Source: https://habr.com/ru/post/1741897/


All Articles