You are on page 1of 10

Visual Basic .

NET Programming

What is ASP.NET
 a web programming technology developed
by Microsoft
 used to create dynamic web pages


Dynamic web page


a web page where page content is
dynamically generated for every request

 successor to ASP

Understanding ASP.NET

* Property of STI
Page 1 of 10

Visual Basic .NET Programming

Overview of ASP.NET
 benefits of using ASP.NET







Code-behind support
Code can be compiled from any
Microsoft .NET-compatible language
ASP.NET pages run side-by-side with ASP
Automatic support for multiple browsers
ASP.NET namespaces provide rich
functionality
Built-in support for web services

Understanding ASP.NET

* Property of STI
Page 2 of 10

Visual Basic .NET Programming

The Response and


Request Objects
 The HttpRequest class is used to
request information such as query string
and form values from a client browser.
Dim strName As String =
Request.Form(txtInput)

 The HttpResponse class is used to send


information such as HTML output and
browser redirection.
Response.Write(<H2> The date is:
& Now.Date & </H2>)

Understanding ASP.NET

* Property of STI
Page 3 of 10

Visual Basic .NET Programming

Maintaining
ClientClient-Side State
 ASP.Net provides a functionality to
maintain state for a Web page when
needed.
 HTTP is a stateless protocol. It cannot
maintain a state over a period of time.
 Ways to maintain client-side state:






View State
Control State
Cookies
Hidden Fields
Query Strings

Understanding ASP.NET

* Property of STI
Page 4 of 10

Visual Basic .NET Programming

Maintaining
ServerServer-Side State
 HttpApplicationState class



used to store application-level information


Application object can be used to share
global data across the application

Application(WebApp_StartTime) = Now

Response.Write(Application Started:
&
Application(WebApp_StartTime))

Understanding ASP.NET

* Property of STI
Page 5 of 10

Visual Basic .NET Programming

Maintaining
ServerServer-Side State
 HttpSessionState class


Session object is used by server to


maintain session state information

Session(WebSession_StartTime) = Now

Response.write(Session started: &


Session(WebSession_StartTime))

 Profile Properties feature




allows programmers to define and store


user setting to be used in the Web
application
allows easy management of user
information
makes the user information available using
a strongly typed API

Understanding ASP.NET

* Property of STI
Page 6 of 10

Visual Basic .NET Programming

Application and
Session State
 used to store information that can be
accessed by other components within the
Web application
 used to share resources and state
management
 HttpApplicationState class contains
an Application property that provides easy
access to variables


Application-level events:

Application_Start
Application_BeginRequest
Application_EndRequest
Application_End

 HttpSessionState class allows you to


store session attributes


Session-level events:
Session_Start
Session_End

Understanding ASP.NET

* Property of STI
Page 7 of 10

Visual Basic .NET Programming

Application and
Session State
 Example:
Sub Application_Start(ByVal sender As
Object, ByVal e As EventArgs)
Initialize the application level
counter
Application(SessionCounter) = 0
End Sub
Sub Session_Start(ByVal sender As
Object, ByVal e As EventArgs)
Increment the application level
counter
Application(SessionCounter) =
Application(SeesionCounter) + 1
Assign new value to session-level data
Session(StartTime) = Now
End Sub
Sub Session_End(ByVal sender As Object,
ByVal e As EventArgs)
Decrement the application level
counter
Application(SessonCounter) =
Application(SeesionCounter) - 1
End Sub
Understanding ASP.NET

* Property of STI
Page 8 of 10

Visual Basic .NET Programming

Web Forms
 have the file extension .aspx
 every ASPX file has a corresponding codebehind file for the code


.aspx file contains definitions for the visual


elements of the Web Form as well as the
link to the code-behind module that
contains the logic and event-handler of the
Web Form
code-behind file is a file with an .aspx.vb
extension

 This class allow you to do the following:





Create methods or event-handling code.


Provide access to many of the commonly
used ASP.NET objects.
Provide event handlers

Understanding ASP.NET

* Property of STI
Page 9 of 10

Visual Basic .NET Programming

Demo: Creating a New


Web Application Project











Open Visual Studio 2005.


File > New Web Site
Select ASP.NET Web Site.
Set Location to File System. Then, set
the location of your Web application.
Set Language to Visual Basic. Click OK.
Rename the aspx file named Default.aspx
to ASPDemo.aspx.
Click on the Source tab.
On the design view, My first ASP.NET
Web page!.
Right-click on the project name and select
View in Browser.
Simply click Yes. A browser will open and
displays the My first ASP.NET Web
page!. in the Web page.

Understanding ASP.NET

* Property of STI
Page 10 of 10