Creating Web Applications by Using Microsoft Visual Studio 2008 and Languages

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Creating Web Applications by

Using Microsoft Visual


Studio 2008 and
Microsoft .NET-Based
Languages
Module 2: Creating Web Applications by Using Microsoft
Visual Studio 2008 and Microsoft .NET-Based Languages

• Overview of Visual Studio 2008

• Creating an ASP.NET Web Application Project

• Overview of the Microsoft .NET-Based Languages

• Creating a Component by Using Visual Studio 2008


Lesson: Overview of Visual Studio 2008
• Why Visual Studio 2008?

• Available Project Templates

• Integrated Development Environment (IDE)

• Demonstration: Using the Visual Studio 2008 IDE


Why Visual Studio 2008?
• One IDE for multiple languages and multiple project types

• Multiple languages within a project

• Multiple project types within a solution

• Support for applications that target multiple versions of


the .NET Framework
• Integrated browser

• Debugging support

• Customizable interface

• WPF, WCF, and Workflow designer and project support


Available Project Templates

• The list of available project templates is based on


your Project type and Template selections
Integrated Development Environment (IDE)

Object Browser
Editor/Browser

Solution
Explorer
Server
Explorer

Properties
Toolbox

Dynamic Help
Task List
Lesson: Creating an ASP.NET Web Application Project

• The Development Process

• Web Application Files

• Web Application File Structure

• Demonstration: Creating a Web Application Project


The Development Process

Create
CreateaaDesign
Design
Specification
Specification

Create
Createaa Create
Createthe
theInterface
Interface Test
Testand
and
New
NewProject
Project and
andWrite
WriteCode
Code Debug
Debug

Build
Build
Visual Studio 2008
Deploy
Deploy
Web Application Files
• Solution files (.sln, .suo)

• Project files (.vbproj, .csproj)

• Web application files


 ASP.NET Web Forms (.aspx)
 ASP.NET Web services (.asmx)
 Classes, code-behind pages (.vb or .cs)
 Global application classes (.asax)
 Web.config file

• Project assembly (.dll)


Web Application File Structure

Documents
Documents Inetpub
Inetpub

Visual
Visual Studio
Studio
wwwroot
wwwroot
Projects
Projects

Solution
Solution ProjectA
ProjectA

Solution.sln ProjectA.vbproj
WebForm1.aspx
Development Files WebForm1.aspx.vb
(Code-behind page)

Assembly Files Bin


Bin
Build ProjectA.dll
Demonstration: Creating a Web Application
Project
• Populate the ASP.NET Web Form

• Add a new ASP.NET Web Form

• Add a new project

• Write code for the button

• Build and debug the solution


Lesson: Overview of the Microsoft .NET-Based
Languages

• Multiple Language Support

• The Common Language Runtime

• Runtime Compilation and Execution

• What Are Namespaces?

• Comparison of the Microsoft .NET-Based Languages


Multiple Language Support
• The .NET Framework is designed to support
many languages
 More than 20 languages currently supported
 Microsoft provides languages such as Visual Basic .NET,
C# and C++

• Benefits of multiple-language support


 Code modules are reusable
 API access is the same for all languages
 The right language is used for the right task
 Performance is roughly equal between all languages
The Common Language Runtime
• One runtime for all . NET-Based Languages

• Manages threads and memory


 Garbage collection

• Enforces code security

• Eliminates DLL versioning problems


 Multiple versions of a DLL can run simultaneously
 Applications can specify a version of a DLL to use
Runtime Compilation and Execution

default.aspx

Which language?

C# code Visual Basic .NET


code

C# Visual Basic .NET


compiler compiler
HT
ML

JIT MSIL
compiler

Runtime
Native
code
What Are Namespaces?
• Group related classes
 Logical, not physical, grouping
 Namespaces are hierarchical

• Decrease naming conflicts

• Imports keyword in Visual Basic .NET code

Imports System.Data.SqlClient

• Using keyword in C# code


using System.Data.SqlClient;

• Implicit object declaration

• Explicit object declaration


Comparison of the Microsoft .NET-Based Languages
• .NET Framework class library is the same regardless of
language
• Performance
 All languages are compiled to MSIL
 Only performance difference is how each language compiler
compiles to MSIL
 The runtime compiles all MSIL the same, regardless of its
origin
• Development experience
 C# is similar to Java, C, Visual C++, and Pascal
 Visual Basic .NET is similar to Visual Basic
• Browser compatibility
 ASP.NET code is server-side code, so browser compatibility is
not an issue
Lesson: Creating a Component by Using Visual Studio
2008

• What Are Classes and Components?

• Creating a Class

• Accessing Components in an ASP.NET Web Form

• Demonstration: Creating a Class in Visual Studio 2008


What Are Classes and Components?

• Classes are groups of code with no user interface

• Components are compiled classes


 Components are compiled as DLL files

• Components are used for sharing code between


applications

component
component

Web
Web Web
Web Windows
Windows
application
application application
application application
application
Creating a Class
• Create a Class Library project in Visual Studio 2008
 Visual Studio 2008 creates a default namespace

• Create methods of the class

Public Class Shipping


Function ShippingCost _
(ByVal sngPrice As Single) As Single
'…
Return (sngShipping)
End Function
End Class

public class Shipping


{
public Single ShippingCost (Single sngPrice)
{
//…
return sngShipping;
}
}
Accessing Components in an ASP.NET Web Form

• Add a reference to the DLL

• Instantiate the class object:


CompanyA.Shipping x =
Dim x As New CompanyA.Shipping new CompanyA.Shipping();

component.dll
component.dll
Namespace CompanyA
namespace CompanyA
Class Shipping {
Function ShippingCost (…) class Shipping
{
End Class
public void ShippingCost (…) { }
End Namespace }
}
• Use the object:
sngShipping = _ sngShipping =
x.ShippingCost(sngPrice) x.ShippingCost(sngPrice);
Demonstration: Creating a Class in Visual Studio
2008
• Create a new Class Library project

• Create a “Hello World” method

• Call it from an ASP.NET page


Creating Web Applications by Using Microsoft Visual Studio
2008 and Microsoft .NET-Based Languages

• Exercise 1: Creating an ASP.NET Web Application Project

• Exercise 2: Creating a Class

• Exercise 3: Calling the Component

Logon information
Virtual machine 2310C_02
User name Student
Password Pa$$w0rd

Estimated time: xx minutes


Lab Scenario

Logon Page
Login.aspx
Benefits
Coho Home Page Page Header ASPState
Winery Default.aspx Header.ascx
Menu
Registration Component
Register.aspx Class1.vb or Class1.cs Web.
tempdb
config

Life Insurance Retirement Medical Dental


Life.aspx Retirement.aspx Medical.aspx Dental.aspx

Prospectus Doctors User Control XML Web


Lab Web Prospectus.aspx Doctors.aspx namedate.ascx Service
Application dentalService1.asmx

XML
Doctors Dentists
Files
Lab Review
Module Review and Takeaways
Review Questions
• How would you select a .NET-based language to create a
new Web application project?
• What role does the common language runtime play in
running an ASP.NET page?
• What is the role of the just-in-time (JIT) compilation?

• List three languages that are currently supported by .NET.

• Why would you create a component for a Web application?


Review for Alpha
• Is there any topic or specific content item in the module
that seemed unclear or unnecessary?
• Is there any content item/related subject area that was
not covered and could be included?
• Did you observe any issues with the technical accuracy of
the content?
• Is the content in the module presented in a manner that
encourages learning? Did the flow of topics seem right?
• Does the lab outline indicate the expected scope of tasks
to be covered? Would you like to suggest any tasks that
could be removed or added?

You might also like