ASP.NET Web Pages, WebForms or MVC? - asp.net

I am thinking about using on of the technologies mentioned in the title but I can't decide which one would be the best for me. I jsut looked at asp.net to get an idea of each technology but I think I need a mix of MVC and WebForms, so that is why I am asking..
I want the MVC structure in the app itself and in the URLs
I want easily create a gridview with paging and sorting and easily map it to an SQL Database
I want to style everything easily via CSS
After I looked at asp.net I think MVC3 would be great for me but I need this in combination with WebForms, as I saw the DataGridView Control will be the best choice for my gridview.
Does someone give me some ideas what the best might be for me ?
After a long time using PHP and HTML/JS I hate it to doe every little step and using precreated Controls I only need to map to a database and customize via css would be a great enhancement to speed development things up!
Thanks!

In my opinion you should opt for MVC 3 approach (given most of your points mentioned) combined with jQuery DataTables. This gives you a best of both worlds - a great data visualiser and all the advantages of MVC 3.
DataTables
http://datatables.net/
DataTables ASP.NET MVC 3 Tutorial on CodeProject
http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part
Additionally if you didn't want to use the jQuery Data Tables you could look into MVC 3 Web grid which is the built in DataGridView equivalent for MVC:
http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

You can use MVC, with aspx, Where you can also use the webforms features that you wished for.
I know there can be a flame war about this, people would suggest different suggestions.
Go for what you want.
All of what you need is possible easily in ASP.NET MVC.

Related

calculating total using angularjs and webforms usercontrol

Im new to using angularjs with webforms.
i am using asp.net 4.0 webforms project. It have a usercontrol(uc.ascx) with a textbox and I dynamically multiple of the usercontrols on a page(Default.aspx)..on this aspx page i have a text box which should display the sum of the values in the textboxes of the dynamically added usercontrol..
can some one help me on how i can achieve this?
I researched all over the internet but could find a proper tutorial that works with usercontrols and angularjs
Well I think your are looking into the wrong direction angularJs isn't similar to knockoutJS probably both of them have double binding, but definitely they are very different.
Angular is a Single page application that's built mostly for CRUD's applications, the typical architecture is to use a restFul web service behind angular (which is going to be your front end) and they communicate using JSON as the communitacion format, been that said, I'd suggest to move on ASP.NET web API and angular
this video could be helpful for you to get the whole picture.
EDIT:
Unfortunately i don't have an specific example for your scenario but I've found a couple of articles that may help you on your journey.
A good example of how to use knockout.js and asp.net definetelly you can look at it and take that as a good source for learn it and apply it to your case.
This is another example using a usercontrol with knockoutjs
take a look to this gibhub repo with and example of the proposed architecture

asp.net MVC GridView Alternatives for Displaying Data

I'm just getting started with ASP.NET MVC and am going through the NerdDinner tutorial. As I'm going through I'm trying to apply what I see with how I will develop my site. I have experience with WinForms and much of what I'm wanting to do is display large amounts of data contained in a database.
I have used DataGridView along with DataSets and DataTable accessing SQLite databases. Going through the NerdDinner tut I see mainly access to SQL Server through Linq to SQL and generating HTML tables rather than using ASP.NET Web UI Components such as GridView.
I like most of the functions and look that the Web UI Components can bring, but I'm not sure if they are necessary. How do you all decide when displaying lots of data from databases what display components to use?
By experience with MVC and ASP .Net Control, your better not user control in a ASP Web form application.
The point is that they work with view state that is against the pattern of MVC.
In the case of your DataGridView what I would do is to loop through the list with a foreach and output a table row.
Phil Haack has a good post of using the jQuery Grid plugin with MVC to create a more "out of the box" grid solution like what you would be used to with the ASP.NET controls you mention.
MvcContrib has a lot of great things to aid with ASP.NET MVC development. In this case the Grid would help you a lot. I've used it in the past and found it to be pretty slick.
If you're using jQuery as well, this article talks about integrating it with the jQuery datable--makes paging and sorting essentially no-effort/painless.

Quick methodology to show client a working demo

I am not starting an argumentative discussion here and this post is not about career development, but from the commercial point of view:
If a company was using ASP.Net MVC as a main methodology to build their web sites and application.
However, ASP.Net MVC takes more time to show a functional application than ASP.Net Web Forms, for example, building domain models would take some time which obviously can't be represented on a UI at that current stage.
My question is, if a client wants to see a functional demo application (just a proof of concept) so he knows that the company he is dealing with is professional and capable of doing that. Would it be better to do that demo in ASP.Net Web Forms only to show the client, and then work on the real application using ASP.Net MVC? If not, what are the (quick) alternatives?, I mean, if we tell the client to wait till we have a working demo (by ASP.Net MVC) we may lose the client and the whole project opportunity.
WebForms being faster than MVC is a myth:
You are not required to have a domain model, just something that represents your database tables. This is the same in WebForms unless you are using SqlDataSource's.
The code in your !IsPostBack or btnSubmit_OnSubmit is almost identical to the HttpPost controller actions. Except with MVC you don't have to write left to write object.FirstName = txtFirstName.Text when you understand how UpdateModel works.
UI is UI. If you know HTML/CSS creating the UI is just as easy. Almost easier in MVC because you don't have to set control properties any longer and all UI can be done in one place.
Fast MVC comes from understanding how to get the most bang from your buck using EditorFor, DisplayFor templates. You'll need to know and understand how to customize your Object.ascx file. With this technique under your belt you won't have to create forms by hand anymore. 2 projects ago we had a site with 100% autogenerated forms. Change a class, change a form. Done!
Another helpful MVC tool is the DataAnnotations attributes. Validation made easy. Customizing these is really easy too. Just create your own ModelMetaDataProvider and starting expanding the validations your application can handle.
The only part of MVC that is slower is displaying a grid. MVC 3 already has a useful grid tool and MVCContrib has had a grid tool out for a year now. I ended up rolling my own, its very simple actually, loop through properties, write <td />'s. < 200 lines of code. This isn't really a benefit to WebForms either. To use WebForms grid components means giving up a lot of quality using ObjectDataSources and the like.
To summarize fast MVC comes from these different techniques:
Object.ascx
ModelMetadataProviders
UpdateModel
DataAnnotations
If you are more advanced and know ORMS like EntityFramework and how to use Automapper your probably going to be even faster.
You can get a demo up and running very quickly in MVC. I could put one together much quicker than with WebForms, and I am familiar with both.
The reliance on convention in MCV will help a lot, binding is based on the names of objects.
If i was creating a quick demo, i would just create a bunch of ViewModels with static data in them, different button clicks etc will just bind one of these ViewModels to the page.
Turbo Fast!
I build prototypes in excel. No logic, no code. just basically screenshots to show the user that we are communicating the same ideas. Create a worksheet for each "View" or screen you need to show. Client's usually only care how "pretty" an application looks vs does it work right.
This also is a benefit as you can include more non-technical users in the prototyping process, since most are used to excel. I can send you an example and the finished production web application, if seeing is believing. I personally learn best by example.
And to your post where you wrote...
I mean, if we tell the client to wait till we have a working demo (by ASP.Net MVC) we may lose the client and the whole project opportunity.
They need to have their expectations adjusted and managed. A lot of bad development has been done quickly over the years, which makes client's ask questions like "Bob did it in 1 hour'. To that I say, you can either have a lousy project fast, that you have to constantly duct tape or a well thought out and well written project that will only need to be enhanced as Bus Reqs change
I think the answer is obvious: use whichever you think makes you faster. There's no point in using MVC if you are faster in WebForms. Especially since this is for a throw-away demo.

Sample project to compare ASP.Net and ASP.Net MVC2

I am trying to explain ASP.Net MVC 2 to my colleagues and the management. I have to develop a sample application in both ASP.Net and ASP.Net MVC 2 to show case the differences between the two.
What would be a good application that can bring out the differences between the two? I am planning to demonstrate performance and testability. Any other key points that I can demonstrate?
Any ideas is really appreciated.
If they're web developers that likes to keep up with all the latest stuff, show 'em your complete control over the generated source. Show them how they can create HTML5 compliant websites with no extra effort. No more (unless you want) viewstate or document wrapping form tags.
You could also show them the extensibility abilities with action filters and action results.
But, as you mentioned, the biggest win for everyone is testability.
Edit:
I can really recommend TardisBank as a great sample application. It uses MVC3 with Razor and RavenDB as the database. The code is well structured and clean.
Show them the page size, that should be helpful

Should I learn ASP.NET if I prefer to have fine-grained control over my site's HTML?

For months, I've been considering downloading Microsoft's express web platform and learning ASP.NET, which I might actually enjoy, seeing as I already do web work with PHP, but am much more comfortable with C#.
However, the primary reason I don't want to do this is that I've always associated ASP.NET with useless spaghetti HTML. The link I posted is an excellent example. Would it be possible to use ASP.NET in a context more similar to PHP, using it to power my site but not leaving the HTML, CSS, and JavaScript to be done by hand for validation and semanticity reasons?
EDIT
I've decided I'm not going to learn ASP.NET and stick with PHP.
While MVC sounds nice, for me it will likely end up being a development/debugging headache.
Things get much better if you use ASP.NET MVC. I recommend you skip ASP.NET WebForms and jump to MVC directly.
If you are going to use Classic ASP.NET Web Forms, you really need to learn how it works to avoid truely ugly html. If you know what you are doing, you can get close to what you want (you can't completely get rid of ViewState & it will do some ugly thing with element IDs)
A lot of the ugliness of Classic ASP.NET occures when people write web forms like they wrote VB 6 Windows applications.
ASP.NET MVC is a good option. It may be the way to go as a starting point; I would like to switch to it myself. I guess my point is that you can get less ugly HTML using Classic ASP.NET.
you're really going to want to check out the asp.net mvc. it allows you to develop in a manner a lot more suited for the web than vanilla webforms.
First of all, ASP.Net, even using webforms, does allow you to have complete control over the markup output. Of course it's easier for some cases than others, but anywhere you find you're not getting the html you want out of a control you can always replace the render behavior with a ControlAdapter.
That said, as others have mentioned you'll probably find it's much easier to get the exact html markup you want using ASP.Net MVC.
MVC.net and WebForms are built upon ASP.net
You can get a decent amount of control with webforms by disabling viewstate and not using any controllers (or very few). Its all in how much you let it do for you
If you are looking to acquire skills in the latest and greatest, then MVC is where you should start but I would also consider whether you will ever be asked to support ASP.Net Webforms. Having an understanding of ViewState is crucial to that end.
For fine grained HTML output, you can produce this in many different ways with classic ASP.Net. There is a growing group of developers who are using a mixture of ASP.Net and microtemplating with Javascript to produce RIA's. This inevitably leads to keeping your html output cleaner so that it can be manipulated with jQuery and CSS.
Learn ASP.NET MVC as it will give you more control over the html generated. Also learning ASP.NET will increase your job opportunities significantly.
My first real development in ASP.NET was with MVC, and I must say I truly miss it now that I'm onto the next project using webforms. Each has it's place and webforms is working pretty well for what I'm doing (also using it as an opportunity to learn about TableAdapters and what not) but I really do miss being able to insert the data I need right into the HTML. That way I know the layout I've built won't get screwed up.
As a framework I enjoy ASP.NET quite a bit, but the controls on the page seems so far removed from anything resembling HTML that there is often a mental disconnect with what I'm typing with what I'm expecting to see. I was that way when I first started HTML though, so I imagine I'll get used to it. When I started with MVC it was overall a much more enjoyable experience coming from a front-end background.

Resources