Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - Inline vs. Code-Behind

I realize that by asking this question, I could have started the apocalypse, but a colleague of mine uses a lot of inline coding in their aspx pages, where as I prefer using the code-behind.

Is there a right and a wrong way here?

like image 506
LiamGu Avatar asked Jul 29 '09 16:07

LiamGu


People also ask

How is an ASP.NET presentation page associated with its code behind?

One tactic for separating code from presentation in ASP.NET is code behind. Code behind is a feature that enables you to take most of or all the code out of an ASP.NET page and place it in a separate file. The code is processed normally; the only difference is where the code is located.

How do you write code behind code in ASPX?

If you use code-behind class files with . aspx pages, you can separate the presentation code from the core application logic (or code-behind). The code-behind class file is compiled so that it can be created and used as an object. This allows access to its properties, its methods, and its event handlers.

What is purpose of code behind?

Code-behind is a convenient mechanism for doing the latter. Code-behind makes it possible to code Web forms in C++, COBOL, and any other language that's supported by a . NET compiler.

What are the advantages of using code behind?

code-behind files allow for a cleaner system implementation. Code-behind files allow a developer to separate the UI display from the UI processing. The only code that should exist in the ASPX file itself is code (typically script) that specifically services the display.


2 Answers

Not unless your coding standard says otherwise.

IMO code-behind helps separation of concerns, so I prefer that, but sometimes just dealing with one file is nice too.

like image 75
Matthew Jones Avatar answered Nov 15 '22 08:11

Matthew Jones


Code-behind is the more traditional and logical place. If it works, it works, but I can't stand doing it in the aspx.

like image 27
scrot Avatar answered Nov 15 '22 07:11

scrot