Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Pro ASP.NET 4.5 in C#
Pro ASP.NET 4.5 in C#
Pro ASP.NET 4.5 in C#
Ebook2,456 pages20 hours

Pro ASP.NET 4.5 in C#

Rating: 0 out of 5 stars

()

Read preview

About this ebook

ASP.NET 4.5 remains Microsoft's preferred technology for creating dynamic websites, providing developers with unrivaled power and flexibility.

Pro ASP.NET 4.5 in C# is the most complete reference to ASP.NET that you will find. This comprehensively revised fifth edition will teach you everything you need to know in order to create well-designed ASP.NET websites. Beginning with core concepts the book progresses steadily through key professional skills. You'll be shown how to query databases in detail, consider the myriad applications of XML, and step through all the considerations you need to be aware of when securing your site from intruders. Finally, you'll consider advanced topics such as using client-side validation, jQuery and Ajax.

By the time you have read this book you will have learned all the skills you need to use ASP.NET 4.5 with confidence.

LanguageEnglish
PublisherApress
Release dateSep 21, 2013
ISBN9781430242550
Pro ASP.NET 4.5 in C#
Author

Adam Freeman

Adam Freeman is an experienced IT professional who started his career as a programmer. He has held senior positions in a range of companies, most recently serving as Chief Technology Officer and Chief Operating Officer of a global bank. He has written 50 programming books, focusing mostly on web application development.

Read more from Adam Freeman

Related to Pro ASP.NET 4.5 in C#

Related ebooks

Programming For You

View More

Related articles

Reviews for Pro ASP.NET 4.5 in C#

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Pro ASP.NET 4.5 in C# - Adam Freeman

    Part 1

    Getting Started

    Adam FreemanPro ASP.NET 4.5 in C#10.1007/978-1-4302-4255-0_1© Adam Freeman 2013

    1. Your First ASP.NET Application

    Adam Freeman¹ 

    (1)

    MILTON KEYNES, United Kingdom

    Abstract

    The best way to get started with ASP.NET is to jump right in. In this chapter, we will show you how to get set up for ASP.NET development and build your first ASP.NET application. The application we will build is simple, but it allows us to show you how to prepare your workstation for ASP.NET development, how the ASP.NET development tools work, and—most importantly—how quickly you can get up and running with ASP.NET. We’ll provide some context and background about the ASP.NET Framework in the next chapter, but this book focuses on coding so that’s what we are going to start with.

    The best way to get started with ASP.NET is to jump right in. In this chapter, we will show you how to get set up for ASP.NET development and build your first ASP.NET application. The application we will build is simple, but it allows us to show you how to prepare your workstation for ASP.NET development, how the ASP.NET development tools work, and—most importantly—how quickly you can get up and running with ASP.NET. We’ll provide some context and background about the ASP.NET Framework in the next chapter, but this book focuses on coding so that’s what we are going to start with.

    Preparing Your Workstation

    You only need two things for ASP.NET development—a Windows 7 or Windows 8 workstation and Visual Studio, which is the Microsoft development environment. You probably have a Windows installation already, but you can usually find some pretty good deals if you need to buy a copy. Microsoft has discount schemes you can use if you are a student or teacher, or if you want to upgrade schemes from older Windows versions. Microsoft also has subscription schemes if you want wider access to its software products. You can get a 90-day trial of Windows 8 from http://msdn.microsoft.com/en-us/windows/apps if you don’t have Windows and you would like to familiarize yourself with ASP.NET development without making a financial commitment.

    You need Visual Studio 2012 to build applications with ASP.NET 4.5, the version of the ASP.NET Framework we use in this book. Several different editions of Visual Studio 2012 are available, but we will be using the one that Microsoft makes available free of charge—Visual Studio Express 2012 for Web. Microsoft adds some nice features to the paid-for editions of Visual Studio, but you won’t need them for this book. In addition, all of the figures throughout this book have been taken using the Express edition running on Windows 8. You can download the Express edition from www.microsoft.com/visualstudio/eng/products/visual-studio-express-products . There are several different editions of Visual Studio 2012 Express, each of which is used for a different kind of development—make sure that you get the Web edition, which supports ASP.NET applications.

    Tip

    You can use any edition of Visual Studio 2012 for the examples in this book. You will see slight differences in some of the dialog boxes and the menu and toolbar configurations, but otherwise you will be just fine.

    Creating a New ASP.NET Project

    Start Visual Studio 2012 and select New Project from the File menu. You will see the New Project dialog box, which, as the name suggests, you use to create new Visual Studio projects.

    You will see a list of the available project types in the left-hand panel of the dialog box. Navigate to Installed ➤ Templates ➤ Visual C# ➤ Web and you will see the set of ASP.NET projects available, as shown in Figure 1-1.

    Tip

    Make sure you select Visual C# and not Visual Basic. You’ll get some very odd behavior and errors if you try to follow our C# examples in a Visual Basic project.

    A978-1-4302-4255-0_1_Fig1_HTML.jpg

    Figure 1-1.

    The New Project dialog box

    Select the ASP.NET Empty Web Application item from the central panel of the dialog box—some of the names of the different project types are similar so make sure that you get the right one. Make sure that .Net Framework 4.5 is selected in the drop-down menu at the top of the screen and set the Name field to PartyInvites. Click the OK button to create the new project.

    Tip

    Visual Studio will set the Solution Name field to PartyInvites to match the project name. A Visual Studio solution is a container for one or more projects, but for all of the examples in this book our solutions will contain just one project, which is typical for ASP.NET Framework development.

    The ASP.NET Empty Web Application is the simplest of the project templates and creates a project that only contains a Web.config file, which contains the configuration information for your ASP.NET application. Visual Studio shows you files in the Solution Explorer window, which you can see in Figure 1-2. The Solution Explorer is the principal tool for navigating around your project.

    A978-1-4302-4255-0_1_Fig2_HTML.jpg

    Figure 1-2.

    The Visual Studio Solution Explorer window

    Adding a New Web Form

    As you saw when you created the Visual Studio project, there are different kinds of ASP.NET applications. For the type of application we describe in this book, content is generated from a Web Form. This is a misleading name, as we explain in Chapter 2, but for the moment it is enough to know that we add content to our application by adding new Web Form items.

    To add a new Web Form to the project, right-click the PartyInvites project entry in the Solution Explorer window and select Add ➤ Web Form from the pop-up menu. When prompted, enter Default as the name for the new item, as shown in Figure 1-3.

    Note

    Throughout this book, we build up each example so that you can follow along in your own Visual Studio project. If you don’t want to follow along, you can download a complete set of example projects from apress.com . We have organized the examples by chapter and have included all of the files you will need.

    A978-1-4302-4255-0_1_Fig3_HTML.jpg

    Figure 1-3.

    Setting the name for the new Web Form

    Click the OK button to dismiss the dialog and create the new item. You will see that Visual Studio has added a Default.aspx file to the project in the Solution Explorer and opened the file for editing. You can see the initial contents of the file in Listing 1-1.

    Listing 1-1. The initial contents of the Default.aspx file

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    http://www.w3.org/1999/xhtml ">

    server>

    form1 runat=server>

    A Web Form file is, at its heart, an enhanced HTML file. The element that has the <% and %> tags gives away the fact this isn’t a regular HTML file, as do the runat attributes present in the head and form elements. We’ll explain what all of this means later, but for now we just want to emphasize that we are indeed working with HTML. In Listing 1-2, you can see that we have added some standard HTML elements to the Default.aspx file.

    Listing 1-2. Adding standard HTML elements to the Default.aspx file

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    http://www.w3.org/1999/xhtml ">

    server>

    form1 runat=server>

    Hello

    This is a new web form

    We have added an h1 and a p element containing some simple text. Nothing is specific to ASP.NET in these elements—they are standard HTML.

    Testing the Example Application

    The Visual Studio toolbar contains a drop-down list with the names of the browsers you have installed on your workstation (click the small down arrow to the right of the name to show the list).

    You can see our list in Figure 1-4, which shows that we have several browsers installed. At the very least, you will have entries for Internet Explorer and Page Inspector (a tool that helps you debug your HTML and that we demonstrate later in Chapter 5).

    A978-1-4302-4255-0_1_Fig4_HTML.jpg

    Figure 1-4.

    Selecting a browser in Visual Studio

    We will be using Internet Explorer in this book because it is always available on Windows workstations. There are occasions when we will use or refer to another browser to demonstrate a particular feature, but we’ll always make it clear when this happens (and we’ll show you the effect with a screenshot if you don’t want to install additional browsers).

    TESTING WITH MULTIPLE BROWSERS

    Although we use Internet Explorer in this book, we recommend that you test your ASP.NET applications using as many browsers as possible, even if you don’t want to install them on your development workstation. Browsers have reached rough parity when it comes to Version 4 of the HTML and Version 2 of the CSS standards, but we are now transitioning to HTML5 and CSS3. This means that there are some useful and exciting features available for web applications, but that you have to test them thoroughly to make sure that they are handled consistently across browsers.

    Ensure that Internet Explorer is selected and then click the button or select Start Debugging from the Visual Studio Debug menu. Visual Studio will compile your project and open a new browser window to display the Web Form, as shown in Figure 1-5. There isn’t much content in the Web Form at the moment, but at least we know that everything is working the way that it should be.

    A978-1-4302-4255-0_1_Fig5_HTML.jpg

    Figure 1-5.

    Displaying the Web Form in the browser

    Here is the URL that Internet Explorer used for our example: http://localhost:60015/Default.aspx

    You will see a similar URL when you start the application, but it won’t be identical. You will see the http:// part (specifying that the HTTP protocol is to be used) and the localhost part, which is a special name that refers to the workstation. The port part of this URL, 60015 in our case, is assigned randomly and you will see a different number. The last part of the URL, Default.aspx, specifies that we want the contents of our Default.aspx file, that is, what you can see in the browser window.

    So what does this URL relate to? Visual Studio 2012 includes IIS Express, which is a cut-down development version of the Microsoft application server used to run ASP.NET applications. IIS Express is installed automatically and you will see an icon in the notification window when it is running. If you right-click on this icon, you can see a list of the ASP.NET applications that you have running and open a browser window to view them, as shown in Figure 1-6.

    A978-1-4302-4255-0_1_Fig6_HTML.jpg

    Figure 1-6.

    Interacting with IIS Express

    When you used Visual Studio to run the application, IIS Express was started and it began listening for requests (on port 60015 for us and, most likely, a different port for you). Once IIS Express had started up, Visual Studio created a new Internet Explorer window and used it to navigate to the URL, which loads our Default.aspx file from IIS Express.

    You can see the HTML that IIS Express and the ASP.NET Framework (which is integrated into IIS) sent to the browser by right-clicking in the browser window and selecting View Source. We have shown the HTML in Listing 1-3 and you will notice that it is different from the contents of the Default.aspx file.

    Listing 1-3. The HTML sent to the browser by IIS Express in response to a request for Default.aspx

    http://www.w3.org/1999/xhtml ">

    post action=Default.aspx id=form1>

    aspNetHidden>

    hidden name=__VIEWSTATE id=__VIEWSTATE

    value="Agt1lWw0aAOOuIlRgFGlnqPKiiOlhPrUBEtN9rfe9Ub4PEAl1oPkeWAELlA9OU4YIwJKj

    rm1ZukKx41t0WQxDSMlETbUqfEgVelN4WkWp1M=" />

    Hello

    This is a new web form

    The HTML sent to the browser is the result of the ASP.NET Framework processing our Default.aspx file. The <% and %> tags have been removed and a hidden input element has been added, but since our Default.aspx file doesn’t do anything interesting at the moment, the file contents are passed to the browser largely unmodified.

    It may not seem like it, but you have created a very simple ASP.NET web application. These are the key points to bear in mind at this point:

    1.

    The user requests URLs that target Web Form files we add to the project.

    2.

    The requests are received by IIS Express, which locates the request file.

    3.

    IIS Express processes the Web Form file to generate a page of standard HTML.

    4.

    The HTML is returned to the browser where it is displayed to the user.

    This is the essence of any ASP.NET application. Our goal is to take advantage of the way that the ASP.NET Framework processes Web Form files to create more complex HTML and sequences of user interactions. In the sections that follow, we’ll build on this basic foundation.

    Creating a Simple Application

    In the rest of this chapter, we will explore some of the basic ASP.NET features used to create a simple data-entry application. We will pick up the pace in this section—our goal is to demonstrate ASP.NET in action, so we’ll skip over detailed explanations as to how things work behind the scenes. We’ll revisit these topics in depth in later chapters.

    Setting the Scene

    We are going to imagine that a friend has decided to host a New Year’s Eve party and that she has asked us to create a web site that allows her invitees to electronically RSVP. She has asked for the following key features:

    A page that shows information about the party and an RSVP form

    Validation for the RSVP form, which will display a confirmation page

    A page that lists the responses from invitees

    In the following sections, we’ll build on the PartyInvites ASP.NET project we created at the beginning of the chapter and add these features.

    Creating a Data Model and Repository

    Almost all web applications rely on some kind of data model, irrespective of the technology used to create them. We are building a simple application and so we only need a simple data model. Right-click the PartyInvites item in the Solution Explorer and select Add ➤ Class from the pop-up menu.

    Tip

    If the Class menu item is missing or disabled, then you probably left the Visual Studio debugger running. Visual Studio restricts the changes you can make to a project while it is running the application. Select Stop Debugging from the Debug menu and try again.

    Visual Studio will display the Add New Item dialog box, which contains templates for all of the items you can add to an ASP.NET project. The Class template will already be selected, so set the name to be GuestResponse.cs and click the Add button. Visual Studio will create a new C# class file and open it for editing. Set the contents of the file so that they match Listing 1-4.

    Tip

    We have used a C# language feature called automatically implemented properties in the GuestResponse class, which you may not be familiar with if you have been working with an older version of the .NET Framework. We explain the C# language features that we use in Chapter 3.

    Listing 1-4. The GuestReponse class

    namespace PartyInvites {

    public class GuestResponse {

    public string Name { get; set; }

    public string Email { get; set; }

    public string Phone { get; set; }

    public bool? WillAttend { get; set; }

    }

    }

    Tip

    Notice that we have defined the WillAttend property as a nullable bool. This means that the property can be true, false, or null. We’ll explain why we chose this data type in the Performing Validation section later in the chapter.

    We will use instances of the GuestReponse class to represent responses from our party guests. We need a repository to store the GuestResponse objects we create. In a real application, this would typically be a database. We will show you how to set up and use a database in Chapter 6, when we create a more realistic ASP.NET application. In this chapter, we just want something quick and simple, so we are going to store the objects in memory. This has the advantage of being easy to do, but it means that our data will be lost each time that the application is stopped or restarted. This would be an odd choice to make for a real web application, but it is fine for our purposes in this chapter. To define the repository, add a new class file to the project called ResponseRepository.cs and ensure that the contents of the file match those shown in Listing 1-5.

    Listing 1-5. The ResponseRepository class

    using System.Collections.Generic;

    namespace PartyInvites {

    public class ResponseRepository {

    private static ResponseRepository repository = new ResponseRepository();

    private List responses = new List();

    public static ResponseRepository GetRepository() {

    return repository;

    }

    public IEnumerable GetAllResponses() {

    return responses;

    }

    public void AddResponse(GuestResponse response) {

    responses.Add(response);

    }

    }

    }

    A repository usually has methods for creating, reading, updating, and deleting data objects (known collectively as CRUD methods), but we only need to be able to read all of the data objects and add new ones in this application. We’ll show you a more typical repository in Chapter 6.

    Creating and Styling the Form

    Our next step is to create the page that contains information about the party and an HTML form that allows guests to respond. We will use the Default.aspx file that we created earlier in the chapter. You can see the changes we have made in Listing 1-6.

    Listing 1-6. Creating the form

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    http://www.w3.org/1999/xhtml ">

    server>

    rsvpform runat=server>

    New Year's Eve at Jacqui's!

    We're going to have an exciting party. And you're invited!

    text id=name />

    text id=email />

    text id=phone />

    We have changed the id attribute value of the form element and added some standard HTML elements to display information about the party and gather the RSVP details from the users. You can see how changes appear by starting the application (either select Start Debugging from the Debug menu or click the Internet Explorer button on the toolbar). As you can see in Figure 1-7, we have a form but it doesn’t look very nice.

    A978-1-4302-4255-0_1_Fig7_HTML.jpg

    Figure 1-7.

    The effect of adding to the form element in the Default.aspx file

    We style elements in a Web Form in the same way we would a regular HTML page—by using Cascading Style Sheets (CSS). To add some basic styles to the application, right-click on the PartyInvites item in the Solution Explorer and select Add ➤ Style Sheet from the pop-up menu. Set the name to be PartyStyles and click the OK button. Visual Studio will add a new PartyStyles.css file to the project. Set the contents of this new file to match the CSS shown in Listing 1-7. Although these are very basic CSS styles, they will improve the appearance of our form fields.

    Listing 1-7. The CSS styles defined in the PartyStyles.css file

    #rsvpform label { width: 120px; display: inline-block;}

    #rsvpform input { margin: 2px; margin-left: 4px; width: 150px;}

    #rsvpform select { margin: 2px 0; width: 154px;}

    button[type=submit] { margin-top: 5px;}

    We associate a CSS style sheet with a Web Form using a link element. You can see how we have added such an element to the head section of the Default.aspx file in Listing 1-8.

    Tip

    If you are unfamiliar with the standards and technologies that underpin web content, such as HTML, CSS, and basic JavaScript, we suggest that you consult Adam’s book The Definitive Guide to HTML5, which is also published by Apress and which is a comprehensive reference.

    Listing 1-8. Adding a link element to the head section of the Default.aspx file

    server>

    stylesheet href=PartyStyles.css />

    Once again, notice that we are using a standard HTML element to link to a file that contains standard CSS styles. (We don’t want to labor this point, but one of the nice things about working with ASP.NET is that it builds on your existing knowledge of web standards.) You can see the effect of the CSS by starting the application, as illustrated in Figure 1-8.

    A978-1-4302-4255-0_1_Fig8_HTML.jpg

    Figure 1-8.

    The effect of adding a link element for a CSS style sheet to Default.aspx

    Handling the Form

    We have a HTML form we can show to people who have been invited to the party, but the same page is displayed over and over again when they click the Submit RSVP button. To fix this, we need to implement the code that will handle the form data when it is posted to the server.

    At the top of the Default.aspx file is the following element:

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    This is known as the Page Directive and the attributes defined by the element provide ASP.NET with details about the Web Form file. We’ll come back to the directive in detail in Chapter 12, but for now we are interested in the CodeBehind attribute. This attribute tells ASP.NET which C# class file contains the code associated with the Web Form. In this case, it is the Default.aspx.cs file, which is the code-behind file for Default.aspx.

    Visual Studio groups together related files as a single item in the Solution Explorer so that large projects are easier to navigate. If you click on the arrow to the left of the Default.aspx entry, you can see the files that Visual Studio has been hiding away, and, as Figure 1-9 shows, one of them is the Default.aspx.cs file referred to by the CodeBehind attribute.

    A978-1-4302-4255-0_1_Fig9_HTML.jpg

    Figure 1-9.

    Expanding the Default.aspx file in the Visual Studio Solution Explorer

    Double-click on the Default.aspx.cs file to open it in the editor and you will see the code shown in Listing 1-9.

    Listing 1-9. The initial content of the Default.aspx.cs code-behind file

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    namespace PartyInvites {

    public partial class Default : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

    }

    }

    }

    The base for our code-behind class is System.Web.UI.Page, which contains a number of useful methods and properties for responding to web requests. We’ll describe the Page class in detail in Part 2 of this book. In this chapter, we are interested in the Page_Load method in our code-behind class that the ASP.NET Framework calls when there are requests for Default.aspx, which provides us with the opportunity to respond to these requests.

    For our example, the Page_Load method will be called once when the page is first loaded and once again when the user submits the form. (We will explain why this happens in Part 2.) In Listing 1-10, you can see the code we have added to the Page_Load method to respond to requests.

    Listing 1-10. Adding code to the Page_Load method

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.ModelBinding;

    namespace PartyInvites {

    public partial class Default : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

    if (IsPostBack) {

    GuestResponse rsvp = new GuestResponse();

    if (TryUpdateModel(rsvp,

    new FormValueProvider(ModelBindingExecutionContext))) {

    ResponseRepository.GetRepository().AddResponse(rsvp);

    if (rsvp.WillAttend.HasValue && rsvp.WillAttend.Value) {

    Response.Redirect(seeyouthere.html);

    } else {

    Response.Redirect(sorryyoucantcome.html);

    }

    }

    }

    }

    }

    }

    We determine if the request we are responding to is the form being posted back to the server by checking the IsPostBack property. If it is, we create a new instance of the GuestResponse data model object and pass it to the TryUpdateModel method, which is inherited from the base Page class.

    The TryUpdateModel method performs a process called model binding where data values are used from the browser request to populate the properties of our data model object. The other argument to the TryUpdateModel method is the object that ASP.NET should use to obtain the values it needs—we have used the System.Web.ModelBinding.FormValueProvider class, which provides values from form data. We describe model binding in more depth in Part 3, but the result of calling the TryUpdateModel method is that the properties of our GuestResponse object are updated to reflect the data values that the user submitted in the form. We then store the GuestResponse object in our repository.

    We want to give the user some kind of feedback when this user submits the form and we do this by using the Response.Redirect method, which redirects the user’s browser. If the WillAttend property is true, then the user is coming to the party and we redirect him or her to the seeyouthere.html file. Otherwise, we redirect the user to the sorryyoucantcome.html file.

    Creating the HTML Response Files

    Not all of the pages in an ASP.NET application have to be generated from Web Form files. We can also include regular, static HTML files. To create the first response file, right-click the PartyInvites item in the Solution Explorer and select Add ➤ New Item from the pop-up menu. Select the HTML Page template from the Add New Item dialog and set the name to seeyouthere.html. Finally, click the Add button to create the HTML file. Ensure that the contents of the file match the contents in Listing 1-11.

    Listing 1-11. The contents of the seeyouthere.html file

    http://www.w3.org/1999/xhtml ">

    See you there!

    See you there!

    Come around 9pm. Fancy dress is optional

    Repeat the process to create the sorryyoucantcome.html file and set the contents to match the contents in Listing 1-12.

    Listing 1-12. The contents of the sorryyoucantcome.html file

    http://www.w3.org/1999/xhtml ">

    Sorry you can't come!

    It won't be the same without you. Maybe next year.

    Bringing the HTML Elements into Scope

    We almost have the basic structure of our application in place, but things are not quite working. We need to tell Visual Studio which file should be loaded when we start the application. It didn’t matter earlier because there was only the Default.aspx file and Visual Studio is smart enough to figure out that this is the file that we want. But now we have a couple of HTML files as well and we need to give Visual Studio a helping hand. Right-click on the Default.aspx entry in the Solution Explorer and select Set as Start Page from the pop-up menu.

    Now you can start the application, either by selecting Start Debugging from the Debug menu or by clicking the Internet Explorer toolbar button. Fill out the form and ensure that you select the Yes option from the select element. When you submit the form, you will see the response that should only be shown when you select the No option, as illustrated in Figure 1-10. Clearly, something is amiss.

    A978-1-4302-4255-0_1_Fig10_HTML.jpg

    Figure 1-10.

    The application always responds with the negative feedback

    The reason for this problem is that ASP.NET only looks for elements that have the runat attribute with a value of server when processing Web Form files. All other elements are ignored and since our input and select elements in the Default.aspx file don’t have this attribute/value combination, the model binding process isn’t able to find the values submitted in the HTML form. In Listing 1-13, you can see how we have corrected the problem.

    Listing 1-13. Adding the runat attribute to the input and select elements

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    http://www.w3.org/1999/xhtml ">

    server>

    stylesheet href=PartyStyles.css />

    rsvpform runat=server>

    New Year's Eve at Jacqui's!

    We're going to have an exciting party. And you're invited!

    text id=name runat=server />

    text id=email runat=server />

    text id=phone runat=server />

    Tip

    There is no value for the runat attribute except server. If you omit the runat attribute or use a value other than server, your HTML elements become effectively invisible to ASP.NET. A missing runat attribute is the first thing you should check for if your Web Forms are not behaving the way you expect.

    Start the application and fill out the form again. This time you will see the correct response when you submit the form, as shown in Figure 1-11.

    A978-1-4302-4255-0_1_Fig11_HTML.jpg

    Figure 1-11.

    The effect of adding the runat attribute to the input and select elements

    Creating the Summary View

    We have the basic building blocks of our application in place and our invitees can RSVP. In this section, we’ll add support for displaying a summary of the responses we have received so that our friend can see who is coming and make plans accordingly.

    Right-click on the PartyInvites item in the Solution Explorer and select Add ➤ Web Form from the pop-up menu. Set the name to be Summary and click the OK button to create a new file called Summary.aspx. Ensure that the contents of this new file match those shown in Listing 1-14.

    Listing 1-14. The contents of the Summary.aspx file

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Summary.aspx.cs

    Inherits=PartyInvites.Summary %>

    <%@ Import Namespace=PartyInvites %>

    http://www.w3.org/1999/xhtml ">

    server>

    stylesheet href=PartyStyles.css />

    RSVP Summary

    People Who Will Attend

    NameEmailPhone

    <% var yesData = ResponseRepository.GetRepository().GetAllResponses()

    .Where(r => r.WillAttend.HasValue && r.WillAttend.Value);

    foreach (var rsvp in yesData) {

    string htmlString =

    String.Format({0}{1}{2},

    rsvp.Name, rsvp.Email, rsvp.Phone);

    Response.Write(htmlString);

    } %>

    This is your first ASP.NET application so we want to demonstrate as many techniques as we can in this chapter. This is why the contents of the Summary.aspx file look very different from the Default.aspx file.

    We’ll go through the different sections of the file in a moment, but the first thing to notice is that there is no form element in the Summary.aspx file. The Web Form name is somewhat misleading and although forms are useful in most web applications, a Web Form file is really just an enhanced HTML file that is processed by ASP.NET. For the Default.aspx file, the enhancements come in the form of the code-behind file so we can use it to deal with form posts. For the Summary.aspx file, we have gone further and used the <% and %> tags to add dynamic content to the HTML generated when the browser requests the file.

    The official term for the <% and %> tags is the service-side scripting delimiters although they are more commonly referred to as code nuggets. There are different kinds of code nuggets available and we added two different types in Listing 1-14. Here is the first one:

    <%@ Import Namespace=PartyInvites %>

    A code nugget whose opening tag is <%@ is a directive. Directives allow you to perform an action that affects the entire Web Form. In this case, we have created an Import directive that brings a namespace from the project into scope so that we can refer to classes without having to qualify the class name.

    Why do we care about namespaces? Since the other code nugget in the listing is a C# code block that will be executed when the page is requested, being able to refer to classes without their namespaces makes the code simpler. The opening tag for a code block is just <%, without any additional characters. (The closing tag for all kinds of code nuggets is always %>).

    In our code block, we have used regular C# statements to generate a set of HTML elements that are rows in the table element listing the people who have accepted invitations. We call the ResponseRepository.GetRepository().GetAllResponses() method to get all of the data objects in the repository and use the LINQ Where method to select the positive responses. We then use a foreach loop to generate HTML strings for each data object:

    string htmlString = String.Format({0}{1}{2},

    rsvp.Name, rsvp.Email, rsvp.Phone);

    Response.Write(htmlString);

    The String.format allows us to compose HTML strings that contain the property values from each GuestResponse object we want to display, and we use the Response.Write method to add the HTML to the output sent to the browser.

    Formatting the Dynamic HTML

    You will notice that we included a link element in the Summary.aspx file that imports the PartyStyles.css file and the styles it contains. We have done this to demonstrate that we style the element that we generate from code blocks in just the same way as the static HTML in the page. In Listing 1-15, you can see the style we added to the PartyStyles.css file for use in Summary.aspx.

    Listing 1-15. Adding styles to the PartyStyles.css file

    #rsvpform label { width: 120px; display: inline-block;}

    #rsvpform input { margin: 2px; margin-left: 4px; width: 150px;}

    #rsvpform select { margin: 2px 0; width: 154px;}

    button[type=submit] { margin-top: 5px;}

    table, td, th {

    border: thin solid black; border-collapse: collapse; padding: 5px;

    background-color: lemonchiffon; text-align: left; margin: 10px 0;

    }

    Testing the Dynamic Code

    To test the Summary.aspx file, start the application and use the Default.aspx page to add data to the repository—remember that we are not storing our data persistently in this example and so you need to reenter the data each time you start the application. Navigate to the /Summary.aspx URL once you have submitted the form a few times and you will see the output illustrated in Figure 1-12.

    A978-1-4302-4255-0_1_Fig12_HTML.jpg

    Figure 1-12.

    Displaying a summary of the positive replies

    Calling a Code-Behind Method

    Although you can include blocks of C# code in a Web Form file, it usually doesn’t make sense to do so because it quickly becomes hard to read and difficult to maintain. A much neater and more common approach is to define methods in the code-behind file and then use a code nugget to call that method and insert the result into the HTML sent to the browser. In Listing 1-16, you can see how we have defined a new method called GetNoShowHtml in the Summary.aspx.cs code-behind file. This method generates the same kind of table rows we produced in the previous section.

    Listing 1-16. The GetNoShowHtml method in the Summary.aspx.cs code-behind file

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Text;

    namespace PartyInvites {

    public partial class Summary : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

    }

    protected string GetNoShowHtml() {

    StringBuilder html = new StringBuilder();

    var noData = ResponseRepository.GetRepository()

    .GetAllResponses().Where(r => r.WillAttend.HasValue

    && !r.WillAttend.Value);

    foreach (var rsvp in noData) {

    html.Append(String.Format({0}{1}{2},

    rsvp.Name, rsvp.Email, rsvp.Phone));

    }

    return html.ToString();

    }

    }

    }

    We can then call this method from a code nugget in the Summary.aspx file, as shown in Listing 1-17.

    Listing 1-17. Calling a code-behind method from the Summary.aspx file

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Summary.aspx.cs

    Inherits=PartyInvites.Summary %>

    <%@ Import Namespace=PartyInvites %>

    http://www.w3.org/1999/xhtml ">

    server>

    stylesheet href=PartyStyles.css />

    RSVP Summary

    People Who Will Attend

    NameEmailPhone

    <% var yesData = ResponseRepository.GetRepository().GetAllResponses()

    .Where(r => r.WillAttend.Value);

    foreach (var rsvp in yesData) {

    string htmlString =

    String.Format({0}{1}{2},

    rsvp.Name, rsvp.Email, rsvp.Phone);

    Response.Write(htmlString);

    } %>

    People Who Will Not Attend

    NameEmailPhone

    <%= GetNoShowHtml() %>

    For this listing, we have used the code nugget whose open tag is <%=. This tells ASP.NET to insert the result of the method into the output sent to the browser, which is a neater and more readable approach than including the code directly in the page. The HTML that is generated is the same as for the previous code nugget, except that we are generating table rows for the people who declined their invitation to the party, as shown in Figure 1-13.

    A978-1-4302-4255-0_1_Fig13_HTML.jpg

    Figure 1-13.

    Using a code nugget to insert the result of a method call into the response

    Performing Validation

    We have almost finished our application, but we still have one problem to solve: users can submit any data they want in the Default.aspx form or even post the form without any data at all. We need to make sure that we get values for all of the form fields so we have good data and know who is and who isn’t coming to the party.

    ASP.NET provides a range of different validation techniques, but the approach we like best is to apply attributes to the data model class, specifying our validation requirements. We revisit validation in Chapter 8 and cover the topic in depth in Part 3, but you can see how we have applied basic validation to the GuestResponse class in Listing 1-18.

    Listing 1-18. Applying validation attributes to the GuestResponse class

    using System.ComponentModel.DataAnnotations;

    namespace PartyInvites {

    public class GuestResponse {

    [Required]

    public string Name { get; set; }

    [Required]

    public string Email { get; set; }

    [Required]

    public string Phone { get; set; }

    [Required]

    public bool? WillAttend { get; set; }

    }

    }

    The Required attribute, which is in the System.ComponentModel.DataAnnotations namespace, tells ASP.NET that we require a value for the property it is applied to. Since we have applied the attribute to all of the properties in the GuestResponse class, we have told ASP.NET that we require properties for all of our data model class properties. This is a pretty basic form of validation because we don’t check to see if the value is useful—just that it has been supplied by the user—but it is adequate for our example.

    Tip

    Required is only one of the validation attributes available. We describe the others in Part 3 of this book.

    When the user submits the form in the Default.aspx file, the ASP.NET Framework will invoke the Page_Load method in the Default.aspx.cs code-behind file. Earlier in the chapter, we showed how we call the TryUpdateModel method to perform model binding. Now that we have added the Required attribute, this method will check to make sure that we have received values for all of the properties.

    We need to make an addition to the Default.aspx file to display messages to the users when there have been problems validating the form data they have posted. In Listing 1-19, you can see the required addition.

    Listing 1-19. Displaying validation errors to the users in the Default.aspx file

    <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs

    Inherits=PartyInvites.Default %>

    http://www.w3.org/1999/xhtml ">

    server>

    stylesheet href=PartyStyles.css />

    rsvpform runat=server>

    New Year's Eve at Jacqui's!

    We're going to have an exciting party. And you're invited!

    validationSummary runat=server

    ShowModelStateErrors=true />

    text id=name runat=server/>

    text id=email runat=server />

    text id=phone runat=server />

    We have added an ASP.NET Web Forms control. A control generates HTML in a page—there are different kinds of control available and they are a convenient way of encapsulating functionality so it can be reused throughout an application. You can create your own controls or use the ones that Microsoft provides. We’ll show you everything you need to know about controls in Part 3 of this book, but we added the ValidationSummary control, which is provided by Microsoft and which displays validation errors.

    This control generates a chunk of HTML that lists the validation problems found with the data in the form. You can see how this works by starting the application and clicking the Submit RSVP button without entering any data, the result of which is illustrated in Figure 1-14.

    A978-1-4302-4255-0_1_Fig14_HTML.jpg

    Figure 1-14.

    Displaying validation error messages

    We could define a CSS style to highlight the error, but we’ll discuss that in Part 3 when we look at validation in depth. For the moment, we want to focus on the last validation error message—the one that tells the user that the WillAttend field is required.

    When we defined the WillAttend property in the GuestResponse class, we used a nullable bool, which can have true and false values, but can also be null. We have used this feature to determine when the user has chosen a value for the WillAttend select element:

    There is a useful interaction between the model binding process and the Required validation attribute that we can exploit. The model binding process will convert the empty string value of the first option element to null, but the Required attribute will generate a validation error if it doesn’t get a true or false value. This mismatch allows us to automatically generate an error if a user doesn’t select the Yes or No values in the drop-down list.

    The only problem with this approach is that the validation message is meaningless to the user, who won’t realize that the select element, which is labeled Will you attend?, corresponds to a data model property called WillAttend. To address this, we need to provide the Required attribute with a different message to display, as shown in Listing 1-20.

    Listing 1-20. Supplying a custom validation message in the GuestResponse class

    using System.ComponentModel.DataAnnotations;

    namespace PartyInvites {

    public class GuestResponse {

    [Required]

    public string Name { get; set; }

    [Required]

    public string Email { get; set; }

    [Required]

    public string Phone { get; set; }

    [Required(ErrorMessage=Please tell us if you will attend)]

    public bool? WillAttend { get; set; }

    }

    }

    We have set the ErrorMessage property to a more useful message, which you can see displayed in the browser if you start the application and submit the form without any data again, as illustrated in Figure 1-15.

    A978-1-4302-4255-0_1_Fig15_HTML.jpg

    Figure 1-15.

    The effect of a custom validation message

    And, with that, we have completed our example application and met all of the requirements we set out to deliver. Invitees can RSVP, but only if they provide values for all of the fields in the form. Our friend can see a list of who has accepted her invitations and who has declined and plan accordingly.

    Summary

    In this chapter, we created a new ASP.NET project and used it to create a simple data-entry application, giving you a first glimpse of the ASP.NET platform. We skipped over a lot of key features, but we showed you the essence of an ASP.NET application—the use of the code-behind file to respond to requests, the use of code nuggets to generate dynamic content, the use of validation to check the input users submit and, finally, the use of prepackaged functionality in the form of controls. In the next chapter, we’ll provide some context for the rest of the book and the approach we have taken to explaining how the ASP.NET Framework works.

    Adam FreemanPro ASP.NET 4.5 in C#10.1007/978-1-4302-4255-0_2© Adam Freeman 2013

    2. Putting ASP.NET in Context

    Adam Freeman¹ 

    (1)

    MILTON KEYNES, United Kingdom

    Abstract

    In Chapter 1, we dived in and showed you how to create your first ASP.NET application. It’s time to take a step back and put what we showed you in context, explaining the nature and purpose of the ASP.NET Framework. In this chapter, we give you a high-level overview of the ASP.NET Framework and describe the rest of the book.

    In Chapter 1, we dived in and showed you how to create your first ASP.NET application. It’s time to take a step back and put what we showed you in context, explaining the nature and purpose of the ASP.NET Framework. In this chapter, we give you a high-level overview of the ASP.NET Framework and describe the rest of the book.

    An Overview of the ASP.NET Framework

    The structure of the ASP.NET Framework is shaped by its history. Microsoft started developing ASP.NET in the late 1990s at a time when a lot of its customers were developing Windows applications using Visual Basic. Microsoft created ASP.NET to bring the Visual Basic programming model to the web development world, including concepts such as drag-and-drop controls, events, and design surfaces, predicated on the idea that the developer didn’t need to have direct knowledge of or control over the underlying HTML and HTTP.

    This may seem like an odd concept today, when every developer has at least a basic knowledge of HTTP and HTML, but it made sense at the time. There was a huge population of Visual Basic developers who expected this kind of abstraction, and Microsoft wanted to protect their market share by giving them web development tools that built on their existing experience. In Figure 2-1, we have shown the basic structure of the early versions of ASP.NET.

    Note

    When we refer to the Visual Basic model, we don’t mean the language itself; rather, we mean the approach, tools, and environment that Visual Basic programmers used to use. The Visual Basic language has struggled since the introduction of .NET. Many programmers have moved to C#, leaving the market segment for Visual Basic .NET much reduced.

    A978-1-4302-4255-0_2_Fig1_HTML.jpg

    Figure 2-1.

    The basic structure of the early versions of ASP.NET

    We have simplified things in Figure 2-1, but there was a set of core services that provided the kind of functions any web application platform requires, such as the ability to process HTTP requests, session management, caching, and so on. One of the key features is the ability to generate HTML dynamically, which Microsoft called Web Forms.

    The name Web Forms was chosen to emphasize the consistency that Microsoft was trying to deliver across desktop and web development. The initial version of the .NET UI toolkit for desktop development was called Windows Forms and both terms originated from the way that most applications written by Microsoft’s developer community were corporate data-entry applications.

    You saw examples of Web Form files in Chapter 1 and, as we explained, they are HTML files that are enhanced by code nuggets (regions in the file denoted by the <% and %> tags). When a browser requests the content of a Web Form, the ASP.NET Framework generates output by combining the static HTML elements of the Web Form file with the dynamic output produced by evaluating the code nuggets and the statement in the code-behind file. Web Forms can contain any HTML and don’t have to be used to gather data, as you saw in Chapter 1.

    Web Forms can also contain controls, which encapsulate the ability to generate commonly required HTML in a reusable way. You saw an example of a simple control when we used a validation summary in Chapter 1. In addition, there are controls available to generate all sorts of HTML content, including some quite sophisticated controls to display and edit data. We get into controls in depth in Part 3 of this book.

    The Evolution and Restructuring of ASP.NET

    In the early days of ASP.NET, you had to use Web Forms to generate dynamic HTML because there was no alternative. When someone said they were building an ASP.NET application, the use of Web Forms was implied. But as ASP.NET matured, Microsoft added support for different approaches to web application development and this has led to the reshaping of the ASP.NET Framework, as shown in Figure 2-2.

    A978-1-4302-4255-0_2_Fig2_HTML.jpg

    Figure 2-2.

    The evolution of the ASP.NET Framework

    There is now a range of different ways of generating dynamic content, including content that isn’t HTML. As a result, we need to be more specific when talking about ASP.NET development. Those parts of the ASP.NET Framework that provide generic services (such as session management, caching, authorization, and so on) are now part of the core ASP.NET platform while those parts that are specific to one of the new additions are self-contained.

    This book is about the core ASP.NET Framework, Web Forms, and the controls that Web Forms supports. There isn’t a clean division between Web Forms and the ASP.NET platform, however. Web Forms are so deeply rooted in the history of ASP.NET that it doesn’t make sense to treat them as separate entities.

    So, when we talk about Web Forms development, we are referring to three things: the capabilities of the core ASP.NET platform, the ability to render HTML from pages with code nuggets, and code-behind classes. When we talk about page controls, we are referring to reusable blocks of Web Forms functionality that provides commonly required features.

    THE OTHER PARTS OF THE ASP.NET FRAMEWORK

    The MVC Framework follows the development style of popular web development frameworks such as Ruby on Rails. The MVC Framework is suited to building large-scale applications that have to be maintained over time, but it contains a lot of concepts that will be new to .NET developers and so has a relatively large up-front investment.

    The MVC Framework is built around a design pattern called MVC, which stands for Model-View-Controller. Applications developed with the MVC Framework are broken into these three areas, called concerns, and through this separation you create applications that are easy to test and maintain. We don’t cover the MVC Framework in this book, but for more information, see Adam’s Pro ASP.NET MVC 4.5 Framework, which is also published by Apress.

    Web API is a new addition to ASP.NET 4.5, and it allows you to quickly and easily create web services that deliver data to application clients. Web API services typically service Ajax requests made by web browsers. The Web API feature shares a common design foundation with the MVC Framework, but it can be used in any kind of ASP.NET application. We use the Web API in Part 4 of the book, where we also explain how to create and manage Ajax requests.

    About This Book

    This book is about using Web Forms and the ASP.NET Framework to create web applications. To create great web applications, developers need to take direct control of the HTML that they generate. This means that we won’t be using the visual design tools that Microsoft provides for Web Forms development. Pretending that web development is the same as desktop development never really worked for ASP.NET Framework, and the results of using the visual tools are very mixed. In fact, we find the results are disappointing and inflexible.

    More broadly, the days when a web developer could get away without understanding at least the basics of HTTP, HTML, and JavaScript have passed. The good news is that Web Forms can be used to develop web applications that are fast and fluid and that generate standards-compliant HTML that works across browsers. All we have to do is jettison the visual development tools and work directly with the contents of our Web Forms files, the way we did in Chapter 1. As you’ll learn, this process is not a hardship and it gives you complete control over the way that your application looks and behaves.

    This book is full of code, markup, and nuggets. This is the book for you if you want to get into detail and take control of your web application. And we recommend you do because ASP.NET Web Forms makes it worth the effort.

    What Do You Need to Know?

    You don’t need to have any prior experience with ASP.NET or Web Forms, but to get the most from this book, you should have some experience in developing with C# and you should have a basic knowledge of C#, HTML, and CSS.

    In Chapter 3, we describe the C# language features that we use in this book. Many .NET developers stick with a specific version of the .NET Framework for years and then jump several versions in a single step. The features we describe in Chapter 3 may be new if you have made a jump to .NET 4.5.

    We also give you a basic introduction to jQuery in Chapter 4. jQuery is an immensely popular open source JavaScript library that makes client-side development in a web application quicker and simpler. Microsoft has embraced jQuery for ASP.NET development and Visual Studio adds it to new ASP.NET Web Forms projects (this didn’t happen in Chapter 1 because we created an empty ASP.NET project, but other project types include the JavaScript files).

    What If I Don’t Have That Experience?

    You may still get some benefit from this book, but you will find it harder going and you’ll have to figure out a lot of the basic techniques required for web application development on your own. Adam has written some books that you may find useful if you want to brush up your skills. If you are new to HTML, read The Definitive Guide to HTML5. This book explains everything you need to know to create regular web content and basic web apps, describing how to use HTML markup and CSS3 (including the new HTML5 elements) and how to use the DOM API and the HTML5 APIs (including a JavaScript primer if you are new to the language).

    We only touch lightly on jQuery in this book because it is a topic unto itself. If you want to learn about it in detail, and we think you should, then read Pro jQuery. Adam covers every aspect of the jQuery library as well as the jQuery UI and jQuery Mobile libraries, which are used to create rich user interfaces in web pages (but which we don’t cover in this book).

    For more advanced topics, read Pro JavaScript for Web Apps, in which Adam describes the development tricks and techniques he uses in his own web development projects. All three of these books are published by Apress.

    What Software and Technology Do I Need?

    You need two things for ASP.NET development: Windows and Visual Studio 2012. If you are able to follow the example in Chapter 1, then you have everything you need to get going.

    When you come to develop your own projects, you will need a platform on which to host them. There are a lot of hosting choices. In Chapter 10, we show you how to deploy a Web Forms application to the Microsoft Windows Azure cloud platform. We picked Azure because it is universally available and easy to work with, and it offers free trials so that you can follow the example without making a financial commitment. There are lots of companies that offer ASP.NET application hosting at every conceivable price point and service quality so you have plenty of options if you choose not to host with Microsoft.

    You can also host your own services by using Windows Server. This means setting up Internet Information Services (IIS), which can be a complex process but has the benefit of giving you complete control over how your service is delivered (although, of course, you also have to take responsibility for ensuring that your infrastructure is secure, scalable and robust). There are some hybrid platforms emerging that allow you to mix the servers on your premises with those in the cloud. There are different services available, but the general goal is to offer flexibility in dealing with peak demands for your application and to service continuity in the face of hardware failure.

    We have switched to cloud services for most of our projects because doing so frees us from having to configure and run servers, but there are lots of other choices and lots of suppliers so you are bound to find something that suits you.

    Are There Lots of Examples in This Book?

    There are loads of examples in this book, and we demonstrate every feature you will need to create first-rate Web Forms applications. You’ll get the most from this book by following the examples and seeing how we build up features and functions, but you don’t have to type all of the code in yourself. Instead, you can download a complete set of examples for every chapter in this book at no charge from apress.com .

    The Structure of This Book

    You have already created your first ASP.NET application in Chapter 1. In Chapter 3, we’ll show you some useful language features and tools for web application development. We will then finish this part of the book by building a realistic Web Forms application called SportsStore, taking you from the point of creating the project to the point of deploying it for public consumption. We wanted to give you a beginning-to-end demonstration because it shows the natural flow of web application development, something that is lost when we focus on individual features.

    Tip

    The PartyInvites application in Chapter 1 and the SportsStore in Chapters 6–10 are the same examples that Adam uses in Pro ASP.NET MVC Framework 4, which might interest you if you want to see how to implement the same functionality using different development techniques. Obviously, Adam would be delighted if you would buy a copy of the book, but you can learn a fair amount just by downloading the source code for the MVC book from apress.com and comparing it with the code in this book.

    Part 1: Getting Started

    This part of the book. We introduce you to ASP.NET and Web Forms and create a realistic application from inception to deployment. Along the way, we cover some of the core language features and tools that are required for effective ASP.NET Web Forms development.

    Part 2: The Core ASP.NET Platform

    In Part 2, we dive into the details of the core ASP.NET platform and the use of Web Forms to generate dynamic content. We show you to how Web Forms actually work and show you how the ASP.NET Framework processes requests. We show you how to manage the request handling process, how to extend the ASP.NET Framework, how to store and cache data and how to handle errors. By the end of Part 2, there won’t be much about the ASP.NET Framework that you won’t understand.

    Part 3: Forms and Controls

    In Part 3, we show you how the ASP.NET Framework deals with HTML forms (which allow the user to provide data to the application) and controls (which generate fragments of responses and can be reused throughout an application). At the heart of both of these topics is data, and we show you the facilities that ASP.NET 4.5 adds to make working with data simpler and easier than any previous version.

    Part 4: Client-Side Development

    In Part 4, we show you the features that ASP.NET provides to make client-side development simpler and easier. These include facilities optimizing script and CSS data, for tailoring content to specific browsers and creating mobile versions of applications.

    Understanding Web Forms

    ASP.NET Web Forms follows an architectural pattern known as the smart user interface (smart UI), which originates in desktop development. In general terms, to build a smart UI application, developers construct a user interface, usually by applying or combining a set of components or

    Enjoying the preview?
    Page 1 of 1