Overview
A web application is comprised of a number of web pages that respond to user requests. Search engines, e-commerce stores, auction sites, social media, and games are examples of web applications on the Internet. This module demonstrates how to begin programming an ASP.NET web application using Visual Studio 2013. Development of web applications is very similar to developing Windows applications using this Integrated Development Environment (IDE). Topics include an introduction to web applications and ASP.NET, creating ASP.NET sites, designing and working with web forms, an introduction to controls, and basic web application testing.
A web application is comprised of a number of web pages that respond to user requests. Search engines, e-commerce stores, auction sites, social media, and games are examples of web applications on the Internet. This module demonstrates how to begin programming an ASP.NET web application using Visual Studio 2013. Development of web applications is very similar to developing Windows applications using this Integrated Development Environment (IDE). Topics include an introduction to web applications and ASP.NET, creating ASP.NET sites, designing and working with web forms, an introduction to controls, and basic web application testing.
Objectives
- Using Visual Studio, create, run and test basic web applications utilizing ASP.Net with VB.NET along with HTML5 and CSS3.
- Given the specifications for a web form, use any server controls presented in the book to design and code the form
Web Applications
- The primary software component that is required to run a web application on a client is a web browser.
- A web application consists of one or more web pages.
- Start a web application by navigating to its URL in a web browser.
- A web page or HTML document that stays the same each time it is requested is called a static web page.
The primary software component that is required to run a web application on a client is a web browser.
A web application consists of one or more web pages.
Start a web application by navigating to its URL in a web browser.
A web page or HTML document that stays the same each time it is requested is called a static web page.
- A web page that changes based on user input or and/or interactions is known as dynamic web page.
- Unlike a static web page, a dynamic web page is defined by a web form.
- When a dynamic web page is requested, the web server forwards the request to the application server.
- A web application runs on a server computer that implements web server software.
A web page that changes based on user input or and/or interactions is known as dynamic web page.
Unlike a static web page, a dynamic web page is defined by a web form.
When a dynamic web page is requested, the web server forwards the request to the application server.
A web application runs on a server computer that implements web server software.
Web Servers
- Internet Information Services (IIS) is the default web server for ASP.NET applications.
- A URL for a web site or application contains the protocol, domain name, path, and file name for that resource.
- If a URL does not contain a file name, IIS will look for default files.
Internet Information Services (IIS) is the default web server for ASP.NET applications.
A URL for a web site or application contains the protocol, domain name, path, and file name for that resource.
If a URL does not contain a file name, IIS will look for default files.
- HTTP is the protocol used by a web browser and web server to communicate.
- A web server processes HTTP client requests and returns HTTP responses.
- An HTTP response contains the address of the browser as well as the HTML document.
- When IIS receives an HTTP request for an ASP.NET page, it forwards the request on to ASP.NET.
HTTP is the protocol used by a web browser and web server to communicate.
A web server processes HTTP client requests and returns HTTP responses.
An HTTP response contains the address of the browser as well as the HTML document.
When IIS receives an HTTP request for an ASP.NET page, it forwards the request on to ASP.NET.
- A web page that is sent from the server to the browser contains only HTML.
- Postback occurs when a user manipulates a control on a web page that returns the page to the server.
- A round trip occurs when the user clicks on a button that posts the current web page back to the server and the server returns the response.
A web page that is sent from the server to the browser contains only HTML.
Postback occurs when a user manipulates a control on a web page that returns the page to the server.
A round trip occurs when the user clicks on a button that posts the current web page back to the server and the server returns the response.
.NET Framework
- The .NET Framework uses the Common Language Runtime and the class library.
- Common Language Runtime (CLR)is the component of the .NET Framework that manages the execution of .NET programs.
- The main purpose of the .NET Framework Class Library is to centralize classes that relevant to .NET application development.
- The .NET Framework that is used in developing an ASP.NET application is called the target framework.
The .NET Framework uses the Common Language Runtime and the class library.
Common Language Runtime (CLR)is the component of the .NET Framework that manages the execution of .NET programs.
The main purpose of the .NET Framework Class Library is to centralize classes that relevant to .NET application development.
The .NET Framework that is used in developing an ASP.NET application is called the target framework.
ASP.NET Requirements
- To develop ASP.NET applications in a local area network development environment, the following must be installed on a server:
- Windows 2003 Server or later
- IIS 6.0 or later
- The .NET Framework
- Without Professional or higher editions of Visual Studio, the following will be needed to develop ASP.NET web applications:
- Visual Web Developer 2010 or later Express Edition
- SQL Server 2008 or later Express Edition
- The Microsoft .NET Framework 4
- To develop ASP.NET applications in a local area network development environment, the following must be installed on a server:
- Windows 2003 Server or later
- IIS 6.0 or later
- The .NET Framework
- Without Professional or higher editions of Visual Studio, the following will be needed to develop ASP.NET web applications:
- Visual Web Developer 2010 or later Express Edition
- SQL Server 2008 or later Express Edition
- The Microsoft .NET Framework 4
ASP.NET
- The Visual Basic code for a web page is stored in a code-behind file in an ASP.NET application.
- The file that contains the HTML code for a web form is the aspx file.
- The aspx file contains both HTML and asp tags.
The Visual Basic code for a web page is stored in a code-behind file in an ASP.NET application.
The file that contains the HTML code for a web form is the aspx file.
The aspx file contains both HTML and asp tags.
- When an ASP.NET 4 page is requested for the first time, the related files are processed and compiled into an assembly.
- When a web page is requested for the second time, ASP.NET creates an instance of the page from the page’s final assembly.
When an ASP.NET 4 page is requested for the first time, the related files are processed and compiled into an assembly.
When a web page is requested for the second time, ASP.NET creates an instance of the page from the page’s final assembly.
Visual Studio IDE
- Forms can be displayed in the Web Forms Designer using the Design, Split, and Source views.
- When designing a form, the Web Forms Designer, Toolbox, and Properties Window are important features.
- Flow layout, which is the default in most versions of Visual Studio, can be supplemented by using tables for structure.
Forms can be displayed in the Web Forms Designer using the Design, Split, and Source views.
When designing a form, the Web Forms Designer, Toolbox, and Properties Window are important features.
Flow layout, which is the default in most versions of Visual Studio, can be supplemented by using tables for structure.
Code Snippets
- A feature of Visual Studio called code snippets can be used to enter common ASP.NET elements. Code snippets are capable of:
- Visual Basic code
- HTML elements
- ASP.NET elements
A feature of Visual Studio called code snippets can be used to enter common ASP.NET elements.
- Code snippets are capable of:
- Visual Basic code
- HTML elements
- ASP.NET elements
Event Procedures
- The Code Editor can be utilized to create event procedures that respond to web form events. An Event Procedure can be started by one of the following:
- Double-clicking outside the body of a form in the Web Forms Designer
- Selecting a control and double-clicking on an event in the Properties window
- Selecting a control from the top left of the Code Editor and an event from the top
The Code Editor can be utilized to create event procedures that respond to web form events.
An Event Procedure can be started by one of the following:
- Double-clicking outside the body of a form in the Web Forms Designer
- Selecting a control and double-clicking on an event in the Properties window
- Selecting a control from the top left of the Code Editor and an event from the top
Maintaining State
- HTTP is considered a stateless protocol in that the server receiving a HTTP request cannot associate a browser’s request with its previous requests.
- To maintain the state of an application, ASP.NET provides view state, session state, application state, and profiles.
HTTP is considered a stateless protocol in that the server receiving a HTTP request cannot associate a browser’s request with its previous requests.
To maintain the state of an application, ASP.NET provides view state, session state, application state, and profiles.
- By default, the EnableViewState property is set to True for a web server control.
- This allows all of the form and control properties affected by code are retained when the form returns from the client’s browser.
- Web page data associated with view state is stored as a(an) hidden (encrypted) input field in a page’s source code.
By default, the EnableViewState property is set to True for a web server control.
This allows all of the form and control properties affected by code are retained when the form returns from the client’s browser.
Web page data associated with view state is stored as a(an) hidden (encrypted) input field in a page’s source code.
Server Controls
- HTML controls are directly mapped to traditional HTML elements.
- The Toolbox of the Web Forms Designer can be used to add a control to a web site.
- The Properties window is used to modify the properties of a control within the Web Forms Designer.
- Web server controls must be converted to HTML before they can be displayed in a web browser.
- Web server controls are always processed on the server side.
HTML controls are directly mapped to traditional HTML elements.
The Toolbox of the Web Forms Designer can be used to add a control to a web site.
The Properties window is used to modify the properties of a control within the Web Forms Designer.
Web server controls must be converted to HTML before they can be displayed in a web browser.
Web server controls are always processed on the server side.
- Server controls can be stored in tables (cells) to allow for better alignment.
- Web server controls are rendered as HTML without asp tags.
- User input in (entered in controls) are returned to the browser in HTML.
- Disabling view state for a control allows a developer to revert a property to its default value each time the page is loaded.
Server controls can be stored in tables (cells) to allow for better alignment.
Web server controls are rendered as HTML without asp tags.
User input in (entered in controls) are returned to the browser in HTML.
Disabling view state for a control allows a developer to revert a property to its default value each time the page is loaded.
- Setting a control’s AutoPostBack to true allows a page to be posted back to the server immediately when the control’s value changes.
- Drop-down list values can be initialized in a procedure in the form’s load event.
- The SelectedIndexChanged event occurs when an item is selected from a drop-down list.
- Coding a procedure for the CheckedChanged event of a control allows a user to process a web form immediately when a check box control is manipulated.
Setting a control’s AutoPostBack to true allows a page to be posted back to the server immediately when the control’s value changes.
Drop-down list values can be initialized in a procedure in the form’s load event.
The SelectedIndexChanged event occurs when an item is selected from a drop-down list.
Coding a procedure for the CheckedChanged event of a control allows a user to process a web form immediately when a check box control is manipulated.
Validation Controls
- A validation control is executed to validate user input when:
- Focus leaves the input control
- Or when a button is clicked that has its CausesValidation property set to True.
- Testing the IsValid property of a web page allows determination of whether or not a validation control has been successful.
- Setting a button’s CausesValidation property to False will stop a validation control from verifying user input when that button is activated.
A validation control is executed to validate user input when:
- Focus leaves the input control
- Or when a button is clicked that has its CausesValidation property set to True.
Testing the IsValid property of a web page allows determination of whether or not a validation control has been successful.
Setting a button’s CausesValidation property to False will stop a validation control from verifying user input when that button is activated.
- Best practices dictate that validation is performed on the server side.
- Validation may be performed on the client only if DHTML is supported by the browser.
- The IsValid property can demonstrate when a validation control fails.
Best practices dictate that validation is performed on the server side.
Validation may be performed on the client only if DHTML is supported by the browser.
The IsValid property can demonstrate when a validation control fails.
Testing
- The Load event of a page occurs every time the page is loaded.
- The IsPostBack property of a web form can test whether or not a page is being posted back to the web server.
- Clicking the Start button in the Standard toolbar or pressing the F5 key will test an ASP.NET application with the Visual Studio provided development server.
- A standalone environment is one in which an application is developed without access to a separate server. This environment is typically more suitable for testing purposes.