Advanced Web Forms

jesse-liberty-v2

Welcome to this review of Advanced Web Forms, which is the second module of the Pluralsight course One ASP.NET From Scratch by Jesse Liberty and Jeff Fritz.

Jesse Liberty has over three decades of experience writing and delivering software projects.

He is the author of 2 dozen books, and has been a Senior Technical Evangelist for Microsoft and a Distinguished Software Engineer for AT&T.

He is a Xamarin Certified Mobile Developer and MVP, Microsoft MVP and Telerik MVP.

Jesse also the host of “Yet Another Podcast”, which is a great show.

Also in this series:

Part 1 – One ASP.NET From Scratch

Advanced Web Forms

Session vs. Application State

This lesson demonstrates the difference between Session State and Application State.

Jesse shows a name and email input form, which saves and retrieves from both types of state.

The syntax for each is similar: we simply use the same pattern with the Session object for Session state and the Application object for Application State. It’s so similar, Jesse even copies and pastes the code for speed.

From running the code in one browser, we can’t tell any difference between these two mechanisms.

But if we open a second browser, we can only retrieve the data which was saved to Application state (not Session state). This is because Session is tried to a particular browser.

Cookies

Jesse adds a label, textbox and submit button to the page.

In the submit button event click handler, we see the code to write a browser cookie.

Once it is written, we can find this in the browser cache.

Controls Introduction

There are many more Web Form controls:

  • Button
  • Calendar
  • CheckBox
  • CheckBoxList
  • DropDownList
  • FileUpload
  • HiddenField
  • Hyperlink
  • Image
  • ImageButton
  • Label
  • LinkButton
  • Literal
  • Panel
  • RadioButton
  • RadioButtonList
  • Table
  • TextBox

Controls

A demonstration of many of these controls including CheckBox, RadioButton, CheckBoxList with ListItem elements, and RadioButtonList, also with list items.

We also see the DropDownList, Label and Submit Button.

Jesse writes the click handler code to process all of the input values, and outputs a screen showing back the information that was captured.

Validation Intro

Jesse explains that Client Side validation is easily spoofed, so professional applications must be validated on the server as well.

In Web Forms, Server Side validation typically requires a postback.

Jesse introduces some validation controls:

  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpresionValidator
  • CustomValidator
  • DynamicValidator
  • ValidationSummary

Required Field Validation Demo

We add a RequiredFieldValidator and tell it which control to validate.

When we run the app we get the error

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’

To fix this we go to Global.asax and add

ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.WebForms

We see how to use Nuget to install jQuery and AspNet.ScriptManager.jQuery

Data Introduction

There are a number of ways of dealing with data in Web Forms:

  • SqlDataSource
  • LinqDataSource
  • ObjectDataSource
  • XMLDataSource
  • SiteMapDataSource
  • AccessDataSource
  • EntityDataSource

There are the following Data Controls:

  • Chart
  • DataList
  • DataPager
  • DetailsView
  • FormView
  • GridView

Data Controls

The Data Controls do a tremendous amount of work for us.

Jesse adds a SqlDataSource and configures it to use a new connection to a Northwind database.

With this in place we can add the GridView control and set it to use this data source to populate it. We see how to edit our columns to display them as we like.

We also see that the Grid View can automatically sort our data, and page it for us.

Part 3 – MVC is coming soon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s