Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A question of style: Inline code in .aspx pages.

A question of style: Inline code in .aspx pages.

Scheduled Pinned Locked Moved The Lounge
htmlasp-netarchitecturequestioncsharp
34 Posts 25 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Maunder

    Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

    R Offline
    R Offline
    R Giskard Reventlov
    wrote on last edited by
    #13

    Logic dictates a clean separation of concerns and nothing brought me more joy than .Net: I would be very reticent about MVC: the concept is great, the execution not so much. besides, 'traditional' Asp.Net is easier to maintain and read. Still, each to their own.

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

    1 Reply Last reply
    0
    • C Chris Maunder

      Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #14

      I haven't done an aspx page in a few years, but I would still try to keep it separate. I want as little as possible in the actual HTML... Of course, I don't fall into the crowd that gets a woody every time some industry pundit postulates about some new paradigm.

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

      1 Reply Last reply
      0
      • H Hans Dietrich

        Indivara wrote:

        Mixing them will mean that you'll probably have to separate them one day.

        Are you sure? You know how Chris is always chasing the latest paradigm du jour. :)

        Best wishes, Hans


        [Hans Dietrich Software]

        G Offline
        G Offline
        Gary Wheeler
        wrote on last edited by
        #15

        I first read that as "paramour per diem" :rolleyes:.

        Software Zen: delete this;

        1 Reply Last reply
        0
        • C Chris Maunder

          Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

          J Offline
          J Offline
          James Simpson
          wrote on last edited by
          #16

          With ASP.NET MVC, when done properly the seperation is still there. Use a good view engine and stick to using display/editor templates, including display templates for lists and you end up with just standard Html.RenderMeSomethingOnThePage calls which pretty much represent the same magic as the blocks a designer would have to deal with. But, in response to your original question - yes, you should seperate (And keep view logic down to a minimum).. but does anyone ever do that? Nobody I have ever worked with did! (including myself)

          James Simpson Web Solutions Developer www.methodworx.com

          1 Reply Last reply
          0
          • C Chris Maunder

            Hans Dietrich wrote:

            considering you will be the one maintaining it.

            I think that's a terrible way to think. Every line of code I write I always think "some poor bastard will have to maintain this one day". Sometimes I make it easy for them. Sometimes I leave them presents. You know - the type your cat sometimes leaves you.

            cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #17

            Chris Maunder wrote:

            I think that's a terrible way to think. Every line of code I write I always think "some poor bastard will have to maintain this one day".

            ... immediately followed by thinking "I need a raise". :laugh:

            3x12=36 2x12=24 1x12=12 0x12=18

            1 Reply Last reply
            0
            • C Chris Maunder

              Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

              cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

              V Offline
              V Offline
              Vark111
              wrote on last edited by
              #18

              Situation: based on the contents of some model property, you have to display a particular DIV as one css class or another. So how do you solve this *without* mixing markup and code? Regardless if you're using MVC or not? Either your model has to have CSS class string constants embeded internally (BAD) or you have to branch in your markup (BAD). So which would you do? Me? I choose to branch in my markup. Deciding which css class to use is very definitely a display concern, so it belongs in the view/aspx/cshtml/whatever.

              P B 2 Replies Last reply
              0
              • J Jorgen Andersson

                Drinking at work! Where do I apply?

                List of common misconceptions

                C Offline
                C Offline
                Chris Maunder
                wrote on last edited by
                #19

                We've had the job posted for ages but no many responses. Ah well, we're short on glasses anyway.

                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                J F 2 Replies Last reply
                0
                • C Chris Maunder

                  We've had the job posted for ages but no many responses. Ah well, we're short on glasses anyway.

                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #20

                  Now that you mention it, I don't recall having seen the job board for ages. Just out of curiosity, do you have a link?

                  List of common misconceptions

                  1 Reply Last reply
                  0
                  • C Chris Maunder

                    Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                    R Offline
                    R Offline
                    Rob Grainger
                    wrote on last edited by
                    #21

                    Actually, I feel that MVC leads to an improved separation of concerns, if not necessarily code and markup. By this I mean that separating the Model from the View and Controller leads to big wins. 1. The Model may be reusable in different areas. I've worked with both Windows and Web services sharing the same model as the page architecture. 2. The Controller and routing architecture allows URI's to be much more sensible, and fits better with RESTful architectures. 3. The .aspx represents the view, so the only code in here should be intimately related to Presentation. With respect to the third, if you find anything other than small fragments in the code, then as usual separate it out and invoke it. Yes, you will still be including some code in the markup, but in a good design this should be minimal. The WinForms alternative can appear to have less code in the markup. To my mind though it obfuscates the real nature of the webs request/response architecture. I'd happily make the sacrifice of placing a small amount of code im markup in exchange for a system where the fundamental model seems closer to the nature of what you're actually dealing with. Seems a vastly improved alternative to the mass of ViewState that travels along with a WebForms page - I like to be able to code in a system and predict reasonably what you get.

                    1 Reply Last reply
                    0
                    • V Vark111

                      Situation: based on the contents of some model property, you have to display a particular DIV as one css class or another. So how do you solve this *without* mixing markup and code? Regardless if you're using MVC or not? Either your model has to have CSS class string constants embeded internally (BAD) or you have to branch in your markup (BAD). So which would you do? Me? I choose to branch in my markup. Deciding which css class to use is very definitely a display concern, so it belongs in the view/aspx/cshtml/whatever.

                      P Offline
                      P Offline
                      pughjl
                      wrote on last edited by
                      #22

                      This is a case I'd like to see discussed some more. I faced this condundrum in a MVVM application. I put the display property (CSS class) in the view model and could simply bind to it in the view. I guess MVVM has that extra layer where this stuff can be buried.

                      1 Reply Last reply
                      0
                      • L Lost User

                        Although I've not given it too much of a look, I couldn't see much advantage in MVCing it over the "Separation of Church and State" that I "grew up on " I hated ASP so much that I developed my own variation, using ISAPI, that allowed for the separation much more than traditional ASP, until ASP.Net came along.

                        ___________________________________________ .\\axxx (That's an 'M')

                        B Offline
                        B Offline
                        Brady Kelly
                        wrote on last edited by
                        #23

                        I did one or two small projects, and may have done some bigger ones if I didn't move away from web dev for a while, where my .asp was little more than a DLL import and method call on a COM component. That object spat out HTML. In hindsight I wrote a forerunner for ASP.NET.

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          The main reason I am not sure about MVC is that I think inline code is an abortion. I'll avoid it at all costs. I LIKE readable web code.

                          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                          B Offline
                          B Offline
                          Brady Kelly
                          wrote on last edited by
                          #24

                          With the 'older' style HTML helpers, partial views, and well written controllers, there need be very little code at all inline, and now with Razor your markup is even cleaner.

                          1 Reply Last reply
                          0
                          • V Vark111

                            Situation: based on the contents of some model property, you have to display a particular DIV as one css class or another. So how do you solve this *without* mixing markup and code? Regardless if you're using MVC or not? Either your model has to have CSS class string constants embeded internally (BAD) or you have to branch in your markup (BAD). So which would you do? Me? I choose to branch in my markup. Deciding which css class to use is very definitely a display concern, so it belongs in the view/aspx/cshtml/whatever.

                            B Offline
                            B Offline
                            Brady Kelly
                            wrote on last edited by
                            #25

                            Vark111 wrote:

                            Situation: based on the contents of some model property, you have to display a particular DIV as one css class or another.

                            I render the model property as JavaScript and use jQuery to conditionally set the class of the DIV.

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                              cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                              M Offline
                              M Offline
                              Michael A Cochran
                              wrote on last edited by
                              #26

                              Personally, I hate inline code and it really has little to do with separation of concerns. It's bitten my butt several times over the years as you try to do things like set page themes or dynamically inject controls in the page processing pipeline. I avoid it like the plague. My recipe for an ASP.Net WebForms aplication... Use jQuery and widgitize or plugin the bejesus out of everything that is even remotely reusable. There should be very few server-side dependencies here as each widget or plugin is highly independent and provides very targeted functionality that serves to extend functionality of the markup in the client; e.g., a datatable widget that adds paging to an HTML table element. Almost everything on the UI is broken into UserControl style reusable blocks. Each UserControl has a javascript controller to manage interactions on the client. Minimize server dependencies in the client controller to AJAX calls to a REST bus to acquire data as needed. Where it makes sense, data is returned as highly semantic markup; e.g., an HTML table element. When you return semantic markup like this, you're not really returning UI (view), you're really returning data (model). On the server side, make them ScriptUserControls (from the AJAX Control toolkit) to allow for easy script dependency injection and use a MVVM or MVP pattern to separate concerns on the server. There tends to be very little code in the ScriptUserControl code-behinds or VM/P's because essentially all they are doing is bootstrapping the client behavior script. The real work is being done by the client behavior and the REST bus. You pass settings and parameters as script properties to the client behavior, so zero inline code (and very little markup) in the .ascx. ASP.Net MVC would probably fit very well here as well - especially in the REST bus implementation. I say probably because, I haven't had an opportunity to try out MVC in my legacy app yet. But I have been able to successfully reuse this recipe and all the client script in a Java appliction based on the Spring Framework, which is nearly identical to ASP.Net MVC. And boy, talk about separation of concerns. All the view is encapsulated in the client scripts. For the most part, zero inline code and super semantic markup. The model is in the classes used by the REST bus to generate the return messages, and the controller is the code-behind for the REST bus. Almost every class has specific and targeted functionality making each class small and easy to understand and ma

                              1 Reply Last reply
                              0
                              • C Chris Maunder

                                Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                P Offline
                                P Offline
                                Paul Gehrman
                                wrote on last edited by
                                #27

                                I definitely prefer keeping all code out of the markup, even though I coded in asp for years and am very comfortable with that approach. To me, this is one the HUGE turnoffs (among others) of MVC, going back to this messy model.

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                  B Offline
                                  B Offline
                                  BobRoeder
                                  wrote on last edited by
                                  #28

                                  I maybe the only one that looks as MVC and inline code as a blessing. Yes by far it is harder to maintain, but the possibilites it can open up far exceeds the ability maintain it. This is probably because I have been programming for nearly 40 years, I have different point of view on coding. I have programmed in Assembly, qbasic, fortran, pascal,c, c++, lisp,sql, html,xml,c#..... I have found .Net in gerneral, until MVC, to be quite limiting. It is more interesting now with MVC. RC

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    We've had the job posted for ages but no many responses. Ah well, we're short on glasses anyway.

                                    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                    F Offline
                                    F Offline
                                    Fabio Franco
                                    wrote on last edited by
                                    #29

                                    Chris Maunder wrote:

                                    Ah well, we're short on glasses anyway

                                    I'll bring a whole set of imported (to you) glasses and the awesome cachaça[^]. Mind handling immigration paperwork? Where do I apply?

                                    1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                                      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                      T Offline
                                      T Offline
                                      TheyCallMeMrJames
                                      wrote on last edited by
                                      #30

                                      Not too long ago I got into a debate with some folks from Thoughtworks over lunch on a Monday. They were attacking dynamic data templates and the whole ASP.NET paradigm. I presented a scenario of a simple, temporary internal application for a small department in a large organization and asked how they would code it. They got into design patterns and unit testing and concern separation and automated UI testing (and on). They guessed it would take a relatively small team about a week to pull it off. Using the templates approach, I had completed the entire thing in 12 hours over the weekend. Which was the correct approach? I think that, like many programming questions (should I unit test this?), separation comes down to size and scope of the project. MVC 3 (especially using Razor) allows us to make the binding bits very clean. You can farm most ifs off to partials and keep your primary views fairly clean that way (binding and loops will remain). I think that over-separation of concern can be as much a problem as muddling together a big fatty-fat-fat page. When you're on a smaller project with limited scope, why not use the abilities of the view engine? Also, why do people seem to be offended by "code in the view"? I actually think that there is code that belongs in the view: why can't I if two divs meant for different flows? Why is that bad? What if UI cues from inline code is a simpler way to create a better, more usable UI than getting caught up in over-engineering and academia debate? Now...I will say that I am also a student of design patterns and MVC itself is an implementation of a classic. On larger projects I tend to give myself a level of protection from both a maintenance and an accountability standpoint; typically that means good test coverage and good practices in dev. But it doesn't mean that the odd bit of inline won't appear...

                                      My Latest: Google Maps in ASP.NET MVC 3 with Razor Tech blog: They Call me Mister James

                                      1 Reply Last reply
                                      0
                                      • C Chris Maunder

                                        Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                                        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                        E Offline
                                        E Offline
                                        EbenRoux
                                        wrote on last edited by
                                        #31

                                        Nowadays I am very cautious of one-size-fits-all solutions. With classic ASP that is what we seemed to get. There was no real separation --- I guess putting in some thought code have lead to better separation (web-classes in VB6 had some of this). So the solutions here seemed to be put everthing on the page. With ASP.NET we got better separation even though it was still possible to place code in the page. But the solution here seemed to be to separate everything. The thing with MVC is that the code I put on the page is view-specific code. It has everything to do with rendering the output. However, when performing operations or retrieving data, etc. these are encapsulated in the relevant classes, and data required by the view is passed in the model. So I don't think it is really going back to where we were but rather a matter of: put code you need on the page and code that shouldn't be on the page in classes. But again, one could've ended up with this solution using the previous options.

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          Back in the dark ages when we wrote ASP pages, our only real choice was to inter-mingle our code and our HTML. We'd write a little HTML, then open a script block with <%, then emit some data, or start a loop, or open a connection to a database or whatever. Then we'd close the block and continue on with HTML. Then came ASP.NET and WebForms and suddenly the code-behind (and then code-beside) model dictated that there was a separation of code and markup. You were meant to be able to scatter your server-side controls onto a page like any other markup, code against it in the code-behind, then send just the .aspx page with the markup to a designer who would make it perfect and who would never be able to break you code, since there was no code on the page. Then came MVC and suddenly we're back to inline code. Well, not necessarily code - more inline binding of the properties of the view-model. Except where you need to loop. And maybe that bit where you need to branch. And maybe that other bit, too. The whole argument for the clean, precise separation of code and markup seems to never be mentioned these days and so I'd like to know how ASP.NET developers feel about this. Regardless of what framework you use, do you mix it up like it's 1999? Do you stick to your guns and keep Church and State separated? Or do you embrace the inline binding of view-model to view and just not get carried away too much. If possible?

                                          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                          M Offline
                                          M Offline
                                          mathomp3
                                          wrote on last edited by
                                          #32

                                          Eh depends on the scale and scope of the project. If its a large project and has a bunch of complexities to it. Then I split the code, if its a table view of some data, or a basic IO database project then I'll "cheat" with MVC and go that route. Really just depends.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups