If given the choice, which path would you take?
ASP.NET Webforms + ASP.NET AJAX
or
ASP.NET MVC + JavaScript Framework of your Choice
Are there any limitations that ASP.NET Webforms / ASP.NET AJAX has vis-a-vis MVC?
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access. Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing an interactive web application with the latest web standards.
The main difference between Webform and MVC is that the Webform follows a traditional event-driven development model while the MVC follows a Model, View, and, Controller pattern based development model. ASP.NET is a web framework developed by Microsoft.
If you want to have a faster development cycle than Web Forms might be the best option. If time, money, and energy to develop an application from the scratch is not a constraint then MVC could potentially be the better option.
As you might be knowing, Ajax is a shorthand for Asynchronous JavaScript and XML. The MVC Framework contains built-in support for unobtrusive Ajax. You can use the helper methods to define your Ajax features without adding a code throughout all the views. This feature in MVC is based on the jQuery features.
I've done both lately, I would take MVC nine times out of ten.
The one time I would choose using asp.net forms development would be to use the gridview control. We are using jquery for our javascript framework with MVC and have not yet found a very good gridview like control. We have something that is functional, but the amount of time we have sunk into learning, tweaking, and debugging it vs using asp.net server side controls has been substantial. One looses all of the nice widgets Microsoft provides out of the box doing non asp.net form development. The loss of those widgets is freeing, and scary at the same time when you first start.
At the end of the day I'm happy we are doing MVC development. My team and I have learned a new framework, (we were only asp.net developers before), and have gotten our hands dirty with html and javascript. These are skills we can take onto other projects or other languages if we ever need to.
Don't let people fool you into thinking that it is a clear cut choice. You can get the best of both worlds. My approach is to create an MVC project, but instead of adding views, add standard asp.net pages, but change the code behind to inherit from MVC.ViewPage like so:
public partial class SamplePage : System.Web.Mvc.ViewPage { protected void Page_Load(object sender, EventArgs e) { } }
If you confine yourself to the single form tag (with runat="server") in the code in front, then you have full code behind access to your standard asp.net server controls. This means you get full server side control of the presentation (eg. using databinding and repeaters) without having to do that old ASP-style code weaving.
protected void Page_Load(object sender, EventArgs e) { IObjectDefinition instance = (IObjectDefinition)ViewData["definition"]; _objectName.Text = instance.DisplayName;//textbox or label DataTable itemVals = new DataTable(); itemVals .Columns.Add("itemName"); itemVals .Columns.Add("itemValue"); IDictionary<string, string> items = (IDictionary<string, string>)ViewData["items"]; foreach (KeyValuePair<string, string> datum in items) { conditions.Rows.Add(new object[] { datum.Key, datum.Value}); } _itemList.DataSource = itemVals;//repeater _itemList.DataBind(); }
The post for any control does not post back to the page, but to the controller. If you remember to use the name property on your server controls then they end up in the FormControls collection for access to your page variables as per standard MVC.
So what do you get?:
What do you lose?
Oh, and for AJAX - jQuery definitely. Making a request to a controller method that returns a JsonResult really simplifies things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With