Вы находитесь на странице: 1из 26

Developing Web Applications

Using
Microsoft® Visual
Studio® 2008
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


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

• Multiple languages in 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

• ASP.NET AJAX and LINQ


Available Project Templates
• The list of available project templates is based on
your Project type and Template selections
Integrated Development Environment

Editor Object Browser

Server Solution
Explorer Explorer

Toolbox Properties

Task List Dynamic Help


Lesson: Creating an ASP.NET Web Application Project
• The Development Process

• Web Application Types and File Structure

• Web Application Files

• Demonstration: Creating a Web Application Project


The Development Process

Create a Design
Specification

Create a New Create the Interface Test and


Project and Write Code Debug

Build

Deploy
Web Application Types and File Structure

• ASP.NET Web Application


project template
 Similar project
structure to
Visual Studio 2003
 Provides tighter control
over a project

• ASP.NET Web Site


project template
 Easier to use
 Provides more features
and additional flexibility
Web Application Files
• Web application files
 ASP.NET Web Forms (.aspx)
 ASP.NET Web services (.asmx)
 Classes and code-behind pages (.vb or .cs)
 Global application classes (.asax)
 Web.config file

• Other files
 Files not based on a programming language
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 control

• 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 supports many languages
 More than 20 languages currently supported
 Microsoft provides languages such as Visual Basic,
Visual 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
?
Visual C# Visual Basic
code code

Visual C# Visual Basic


compiler compiler

HTML

JIT compiler
MSIL

Runtime

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

• Decrease naming conflicts

• Keyword: using (Visual C#), Imports (Visual Basic)

[Visual C#]
using System.Data.SqlClient;

[Visual Basic]
Imports System.Data.SqlClient

• Implicit and 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
 Visual C# is appropriate for Java, C, and Visual C++
developers
 Visual Basic is appropriate for Visual Basic 6.0 developers
• 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

Web Web Windows


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


[Visual C#]
public class Shipping
{
public Single CalShipping (Single price)
{
...
return cost;
}
}

[Visual Basic]
Public Class Shipping
Function CalShipping (ByVal price As Single) As Single
...
Return (cost)
End Function
End Class
Accessing Components in an ASP.NET Web Form
• Add a reference to the DLL

• Instantiate the class object:


[Visual C#] [Visual Basic]
CompanyA.Shipping shippingObject = Dim shippingObject As New _
new CompanyA.Shipping(); CompanyA.Shipping

namespace CompanyA
{ Namespace CompanyA
class Shipping Class Shipping
{ Function CalShipping (…)
public void CalShipping (…) { } End Class
} End Namespace
} component.dll component.dll

• Use the object:


cost = cost = _
shippingObject.CalShipping(price); shippingObject.CalShipping(price)
Demonstration: Creating a Class in Visual Studio 2008
• Create a new Class Library project

• Create a method that returns a string

• Call the class from an ASP.NET page

• Create a class in the App_Code folder


Lab: Creating Web Applications by Using Microsoft
Visual Studio 2008 and Microsoft .NET-Based Languages
• Exercise 1: Creating an ASP.NET Web Site

• Exercise 2: Creating a Class

• Exercise 3: Calling the Component

Logon information

Virtual machine 2310C-LON-DEV-02


User name Student
Password Pa$$w0rd

Estimated time: 40 minutes


Lab Scenario

Master Page
Logon Page benefitsMaster.master
login.aspx
Benefits Lab Web benefitsMaster.master

Home Page Application


ASPState
Default.aspx
Default.aspx Page Header
header.ascx
header.ascx
Menu Component
Registration Benefits.cs
Benefits.cs or
or Benefits.vb
Benefits.vb
register.aspx TempDB
Web.
config

Life Insurance Retirement Medical Dentists


life.aspx
life.aspx retirement.aspx medical.aspx dental.aspx

Prospectus
prospectus.aspx
prospectus.aspx Doctors User Control XML Web
LINQ to SQL doctors.aspx nameDate.ascx Service
Classes DentalService1.asmx
Doctors.dbml

Doctors Dentists
XML Files
Lab Review
Review Questions
• How did you create a Web site?

• When you create a Web site, what folders or files does


Solution Explorer display?
• Can you think of a reason why Default.aspx has an
associated code-behind file?
• How can you add projects to a Web site?

• What type of references can you add to your Web site?


Module Review and Takeaways
• Review Questions

• Real-World Issues and Scenarios

• Tools

Вам также может понравиться