Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Making Websites with ASP.NET

0 (0 Likes / 0 Dislikes)
  • Embed Video

  • Embed normal player Copy to Clipboard
  • Embed a smaller player Copy to Clipboard
  • Advanced Embedding Options
  • Embed Video With Transcription

  • Embed with transcription beside video Copy to Clipboard
  • Embed with transcription below video Copy to Clipboard
  • Embed transcript

  • Embed transcript in:
    Copy to Clipboard
  • Invite a user to Dotsub
[ASP.NET] [www.ASP.net] [Scott Hanselman] Hi, I'm Scott Hanselman, and I work at Microsoft in ASP.net, Azure, and web tools. I want to talk to you today in this video about making Web sites with ASP.net. It can be a little bit overwhelming, and it seems like there's a lot of different choices. But it's good to remember that there's just one ASP.NET underneath this. Each of these are different ways to structure your application and each one values slightly different things. But it's all one ASP.NET at its core. So—you can have an ASP.NET web forms site that also has components of MVC and perhaps a web API. You can have a web pages site that's also a single page application that has a lot of JavaScript; you can mix and match. And it's all one ASP.NET, but each technology values slightly different things. So—for example—web forms has a very familiar control-based programming model that if you've every brought in a data grid or a list view— you are even going to have third party controls. And these will encapsulate some of the complexities of HTML and the web and make things a little bit simpler for someone who is comfortable with that event-based programming model. ASP.NET MVC—on the other hand—gives you absolute control of your markup but doesn't give you a lot out of the box. You have to decide how you want to make your application. It supports unit testing and techniques like Agile methodologies. And it's very, very flexible and extensible. If you're just getting started you might consider ASP.NET web pages. This is a single page model for doing your markup and your code. And there's no need to build a project; you just write your code and hit refresh. And it makes it easy to move to ASP.NET MVC in the future because ASP.NET web pages uses Razor—which is a technique in a syntax for writing your web pages. Now—I am going to show you each of these, and you can make the decision for yourself. But—rest assured—there's lots and lots of resources available to you on the Web site here. And you can mix and match these as you like. Let's take a look at what the dialogue box looks like. If I was going to say file, new project within Visual Studio— I'm using Visual Studio 2013. It pops up and says make a new ASP.NET Web site. I can pick a base template—like I want to start with MVC, but if I think I might have web forms later or have a web API I can add those as well; I could start with an entirely empty template or a mobile one. It's really up to me. Let's take a look at a web forms example first and we'll move from there. I've put a little person class in this application, so a person has an ID and a first name and a last name. And I've gone and I've scaffolded out a person class. So I've dynamically generated a person section of my Web site using scaffolding. So this has given me CRUD—create, read, update, and delete pages kind of for free. So—for example—if I look at this person page here you see an ASP.NET web forms; I've got a list view. And it says that person ID is kind of the unique identifier for a person. And it's going to auto generate those columns for me. I've marked that actually as false because I want to auto generate them myself. I have got my table head here with my first name, my last name, and my birth date. And then down here at the bottom we've said dynamic control, so it's going to generate the HTML that I need for my first name, for my last name, and my birth date control. If I go and run this application you can see I've got people list. I'll hit create new, put in a person, put in a silly birthday, and hit insert. And I'm—you know—creating my data in the database right now. Let's make him really old. I can then go and hit edit or delete. Now—notice when I say edit here it says Person/Edit/1. If I look in Visual Studio I can see that there is a person folder, and there's an edit page. Within this edit page we've got a control called form view. And that is managing that form, so this is this idea of a control-based model. I've got an update method for update item. If I look at the code behind for edit— when an item gets updated we'll go and we'll talk to the database. We'll find the person that we're updating. And then we're going to try to update that person object by looking at the HTML form. And then if that works we'll go and save the changes. So there's an interaction between this edit form and the controls on it and the code behind. And I could bring in different controls if I wanted to. Here I am using an ASP.NET form view. I could bring in a data grid or change the way that I wanted to do this. Now—I'm editing a person. In this case I'm using a dynamic entity to automatically give me this entire form, so we're hiding some of the complexity and generating the HTML ourselves. So that's ASP.NET web forms—just at the highest level. But to juxtapose that with MVC let's switch over to an MVC application that basically does the same thing and see what the difference is. So this is now ASP.NET MVC. I'm also going to visit /person, similar page, I'll go and I'll put in data as well. This is in a different database. And hit create. It looks the same, acts the same, you'll notice that the URL is the same. So you get friendly URLs no matter what. You don't necessarily have to have a trade off when picking web forms versus MVC. But the programming model is different. We still have a person class, but with MVC we've got a person controller. So the person controller has a GIT method for person. This is being routed to from ASP.NET routing, and then we're calling index. Model-view controller values separation of concerns. So—this means that there is a model that represents what's in our database. There is a controller that handles the interactions between that model. And then the view then has the data passed to it. So—the model comes from the database, the controller takes that model, does something with it, and then hands it over to the view. So in this case we hit /person. We go off to the database, we get the model, and then we pass that into the view. The view for person is down here. Instead of a control-based model we are using a thing called ASP.NET helpers. These are little methods that are going to output that data, so it's a little bit more—a little bit more detailed—a little bit more attention to detail. I'm having to think about things that I wouldn't have had to think about, but I've got possibly a little bit more control. Here I'm saying for each item within that model go and display the first name, the last name, and the birth date. The result if that HTML that represents a person is still coming out on the page, but it's being done in a slightly different way. Again—one is not better than the other, but they're different. So—we've seen MVC and web forms—and be sure to note that there's lots of places on the Web site that you can see this stuff in detail. I would encourage you to check out ASP.NET/MVC and ASP.NET/webforms. We've got free videos that go on for days. You can go out and search for ASP.NET jumpstart, and we've got eight hours of tutorials to explain this stuff in detail. So—this is just a really short video. One other thing though is web pages. Now web pages is different from both of those in that it's more like php or classic ASP where everything is encapsulated within a single page. So here's my default.cshtml—you'll notice that there's no .CS files. There's no code behind. There's no controllers. I would actually just write the code directly here. So I could declare my variables inside of the same page that I create my HTML. So here's some HTML, and then within it it is a call to go and get the title of the page. This is called Razor—this idea of mixing your HTML and your code. This is used in ASP.NET MVC except web pages doesn't have this sense of separation that MVC does. So—with web forms you get a control-based model. It's a very comfortable for doing text boxes over data— large amounts of data. Times when you don't necessarily want to know all the details of the web MVC gives you this model-view controller separation. It's a recognized pattern and a very comfortable pattern. And web pages which can also be done in web matrix which is a free IDE that you can get or the free version of Visual Studio. It lets you have a single page model. These—again—can be mixed and matched and talk to back end services. Go and check out the APIs video, and we'll talk a little bit about web API. There is also the Signal R video where we talk about the real-time web. And then also a video on tooling that will explain to you how this Visual Studio tool works and what are some of the things that it gives you over just using a text editor. I hope that you enjoy ASP.NET and have as much fun writing your applications in it as we did writing the framework. Thanks a lot. [Microsoft ASP.NET] [www.ASP.net]

Video Details

Duration: 10 minutes and 35 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 6
Posted by: neudesicasp on Aug 7, 2013

Scott Hanselman explains One ASP.NET and gives an overview of how to make a website with ASP.NET.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.