4192312•

Uhg. I cringe at the idea.

4
SymetriXOP•

Well I did try to be clear that this is only for people looking to go the mvc route. If you like web forms then rock on!

2
4192312•

I enjoyed the article. I want to move our codebase to MVC but reading this just makes me realize how much work it will be. Someday...

2
[deleted]•

Can you give a few bullets on the upside of MVC vs. web forms?

1
SymetriXOP•
  • MVC is a better framework for doing custom html/css/javascript (such as integrating a 3rd party javascript library, using a css framework, etc)
  • Web Forms is better if you don't know much about web-specific technologies and would like to keep it that way and just write as much c# as possible and let the framework do all the "dirty" work for you
  • MVC is new and so people are still trying to figure out the best way to do things, you may spend more time in MVC at first but most people who do an MVC project never go back
1
[deleted]•

OK, but call me lazy... I use the Telerik UI framework extensively. The AJAX and XMLHTTP panels. I also avoid putting code in code behind, instead using my own namespaces and classes. So, I let the UI framework vendor's tools manage the client side stuff (because REAL programmers should not have to fuck with the make-pretty) and I put application logic away from pages and db logic on the SQL Server. To be honest, the whole 'markup language' and 'stylesheets' and 'graphics files' mishmash is a massive, ugly kludge. Web programming is a mess that will never be elegant as long as we're using document readers (browsers) to render the UI - seriously, markup languages? I was really beginning to like Silverlight, but I don't know whether MS is going to treat that like a red-headed stepchild now after Win8/Metro/HTML/CSS

1
i8beef•

Nice article. I'll bookmark that. The problem is that so many people pile all their business logic into the actual page code behinds instead of abstracting out into other layers... If you do it right, WebForms / MVC is just the interface / cross cutting concerns layer, and you can drop in the MVC stuff as a replacement UI instead of a complete replacement of the entire application.

But this article is an excellent beginners guide to starting to make those abstractions for people who didn't design things that way in the first place. Thanks!

2
bzBetty•

"drop in" feels a bit too casual to me. surely you don't spend extra time abstracting your code just in case you might replace one of the bits at somepoint in the future. Reminds me of a post from Ayende - http://ayende.com/blog/4567/the-false-myth-of-encapsulating-data-access-in-the-dal

1
i8beef•

Ayende is a pretty smart guy, but his opinion here is pretty colored. He is right, you don't need to abstract the data access method in every app, but completely wrong about not doing it in any app. I've had to rip out NHibernate now twice for performance reasons from apps, and that would have been much harder to do had the dependency not been wrapped in a persistence layer.

But then, I'm not talking just about the persistence mechanisms.

I'm talking about abstracting the entire application's logic into a separate library with (ideally) a single API interface. Again, this doesn't make sense in your 200 line app, but in anything non-trivial that may need, say, a service layer at some point, this is absolutely a good practice for future growth. It even allows you to spread the application logic onto multiple servers in a cluster easier (through a service layer) for load balancing, etc.

One more time: This only makes sense in non-trivial apps, which I don't think is what Ayende was talking about.

But again, you can think of WCF, WPF, WebForms, and MVC (or whatever) as all being drop in UIs to the actual application code. Authentication, authorization, and other cross cutting concerns belong in these UI layers (They become glue code layers pretty much). Drop in is relative of course, as these layers are still usually pretty complicated in and of themselves... perhaps "pluggable" is a better word?

I don't think that is crazy at all. It's basic Tiered Development practice, and wrapping of dependencies so your code is only dependent on your own code. You've never had to rip out library dependencies and switch to a different one? Because I've done it so many times that I'm sold on that practice.

2
[deleted]•

[deleted]

1
SymetriXOP•

Good points, I'll try and update the post with that. Thanks!

1
rossisdead•

I agree entirely with Step 2, but it's not as easy as just turning off viewstate and being done with it. If you make use of setting the visibility of a control, disabling viewstate on an invisible control will cause it to forget its previously posted value(unless the control uses ControlState instead).

1
SymetriXOP•

Very true, any time you turn off viewstate you'll have to set properties like "visible" each time the page loads, and you can't rely on a post-back to remember how the page should look.

You could, however, use a querystring value to set these types of values. But you will have to know to do this.

1
rossisdead•

err, not what I meant, but close enough. What I mean is if you have a TextBox that has its Visible property set to false, if there's no ViewState/ControlState being used to persist its Text value then it'll end up being lost.

1
SymetriXOP•

I know what you mean; anything not actually on the page as a form field is lost.

1
siqniz•

You can do it 1 step just use MVC, its almost seemingly self explanatory using BASIC html controllers. Finding bug in MVC because of the routing you can easily navigate your way to the problem.

1
[deleted]•

Note: Use <%: , not <%= for code in the .aspx, <%: is the equivalent of Server.htmlEncode(), so it stops any XSS.

1