C# Unit 3 - 1
C# Unit 3 - 1
Introduction to asp.net
ASP.NET is a web development platform, which provides a programming model, a
comprehensive software infrastructure and various services required to build up robust web
applications for PC, as well as mobile devices.
ASP.NET works on top of the HTTP protocol. and uses the HTTP commands and
policies to seta browser-to-server bilateral communication and cooperation.
ASP.NET is a part of Microsoft .Net platform. ASP NET applications are compiled codes, written
using the extensible and reusable components or objects present in .Net framework. These
codes can use the entire hierarchy of classes in .Net framework
The ASP.NET application codes can be written in any of the following languages:
● C#
● Visual Basic Net
● Jscript
● J#
ASP.NET is used to produce interactive, data-driven web applications over the internet It
consists of a large number of controls such as text boxes, buttons, and Labels for assembling,
configuring, and manipulating code to create HTML pages.
ASP.NET Web Forms Model
ASP.NET web forms extend the event-driven model of interaction to the web applications. The
browser submits a web form to the web server and the server returns a full markup page or
HTML page in response.
All client side user activities are forwarded to the server for stateful processing. The server
processes the output of the client actions and triggers the reactions.
Now, HTTP is stateless protocol. ASP NET framework helps in storing the information regarding
the state of the application, which consists of:
● Page state
● Session state
The page state is the state of the client, ie., the content of various input fields in the web form.
The session state is the collective information obtained from various pages the user visited
Let us take an example of a shopping cart User adds items to a shopping cart. Items are
selected from a page, say the items page, and the total collected items and price are shown on
a different page, say the cart page. Only HTTP cannot keep track of all the information coming
from various pages. ASP.NET session state and server side infrastructure keeps track of the
information collected globally over a session.
The ASP.NET runtime carries the page state to and from the server across page requests while
generating ASP.NET runtime codes, and incorporates the state of the
server side components in hidden fields. This way, the server becomes aware of the overall
application state and operates in a two-tiered connected way.
The ASP NET Component Model
The ASP.NET Component model provides various building blocks of ASP.NET pages.
Basically it is an object model, which describes:
Server side counterparts of almost all HTML elements or tags, such as <form>and <input>.
Server controls, which help in developing complex user-interface. For example.
the Calendar control or the Gridview controL.
2
VB.NET
VB.NET is known as Visual Basic.NET. VB.NET is a simple, object-oriented programming
language developed by Microsoft in 2002, and it is the successor of Visual Basic 6 (VB6)
language, that implement on the .NET Framework. One of the best features of the VB.NET
language is that its program can also run on mono (multi-platform), which means that it is not
restricted to run on the Windows operating system; moreover, it can also run on Linux and Mac
OS. The Application built using the VB.NET is much secure, robust, high-performance, and
easy to develop.
There is some VB.NET application:
● Console Application
● Mobile application
● Windows forms Application
● Window control library
● .Net website
C#
C# is an open-source, general-purpose, object-oriented programming language that was
developed by Microsoft in the year 2000, which runs on the .NET Framework. Furthermore, this
language is also got certified as a standard programming language by the ECMA and ISO. The
main purpose of using the C# programming language is that it is used to share information as
well as services across all web services. It also enables the developer to develop a robust,
secure, and portable application easily.
Some of the application are listed below:
● Window and web-based application or services
● Distributed application
● Database application
● Difference Between VB.NET and C#
4
Each ASP NET application can have one Global.asax file. Once you place it in the appropriate website
directory, ASPNET recognizes it and uses it automatically. For example, if you add the Global.asax file
shown previously to a web application, every web page in that application will include a footer.
ASP.NET CONFIGURATION
Every web application includes a web.config file that configuration fundamental setting everything from
the way error message are so to the security setting that lock out unwanted visitor you will consider the
setting in the web.config file throughout this book
(And there are many more settings that you uon't consider in this book, because they're used
much more rarely.)
The ASPNET configuration files have several key advantages:
They are never locked: You can update web.config settings at any point, even while your
application is running. If there are any requests currently under way, they'll continue to use the
old settings, while new requests will get the changed settings right away.
They are easily accessed and replicated: Provided you have the appropriate network rights, you
can change web.config file from a remote computer. You can also copy the web.config file and
use it to apply identical settings to another application or another web server that runs the same
application in a web farm scenario.
The settings are easy to edit and understand: The settings in the web.config file are human
readable, which means they can be edited and understood without needing a special
configuration tool.
In the following sections, you'll get a high-level overview of the web.config file and learn
how ASPNET'S configuration system works.
The web.config File
The web.config file uses a predefined XML format. The entire content of the file is nested in a
root <configuration> element. Inside this element are several more subsections, some of
which you'll never change, and others which are more important.
Here's the basic skeletal structure of the web.config file, with the three most important
sections highlighted in bold:
10
{
Currency.Items.Add("Euro");
Currency.Items.Add("Japanese Yen");
Currency.Items.Add("Canadian Dollar");
}
}
12
Page Class
One control you haven’t considered in detail yet is the Page class. As explained in the previous
chapter, every web page is a custom class that inherits from System.Web.UI.Page. By inheriting
from this class, your web page class acquires a number of properties and methods that your
code can use. These include properties for enabling caching, validation, and tracing, which are
discussed throughout this book. Table 5-9 provides an overview of some of the more
fundamental Page class properties, which you’ll use throughout this book.
14
15
This table omits some of the more specialized controls used for data, navigation, security, and
web portals.
Web Control Events and AutoPostBack
The previous chapter explained that one of the main limitations of HTML server controls is their
limited set of useful events—they have exactly two. HTML controls that trigger a postback, such
as buttons, raise a ServerClick event. Input controls provide a ServerChange event that doesn’t
actually fire until the page is posted back.
ASP.NET server controls are really an ingenious illusion. You’ll recall that the code in an
ASP.NET page is processed on the server. It’s then sent to the user as ordinary HTML. Figure
6-11 illustrates the order of events in page processing.
16
17
Rich Controls
ASP.NET provides large set of controls. These controls are divided into different categories,
depends upon their functionalities. The followings control comes under the rich controls
category.
● FileUpload control
● Calendar control
● AdRotator control
● MultiView control
● Wizard control
19
FileUpload control
FileUpload control is used to browse and upload files. After the file is uploaded, you can store the file on
any drive or database. FileUpload control is the combination of a browse button and a text box for
entering the filename.
The FileUpload control supports the following important properties.
Calendar control
Calendar control provides you lots of property and events. By using these properties and events
you can perform the following task with calendar control.
Select date.
Selecting a day, a week or a month.
Customize the calendar's appearance.
The Calendar control supports three important events:
When you select a date, SelectionChanged event will fired and displays the date in a label
controls. In this example the date format is MM/DD/YYYY.
20
AdRotator control
AdRotator control is used to display different advertisements randomly in a page. The list of
advertisements is stored in either an XML file or in a database table. Lots of websites uses AdRotator
control to display the advertisements on the web page.
Important properties of AdRotator control.
ImageUrl: The URL of the image that will be displayed through AdRotator control.
NavigateUrl: If user clicks the banner or ad then the new page opened according to givenURL.
AlternateText: It is used for displaying text instead of the picture if picture is not displayed. It is also used
as a tooltip.
Impressions: It is a number that sets how frequently an advertisement will appear.
Keyword: It is used to filter ads or identifies a group of advertisement.
MultiView control
MultiView control can be used when you want to create a tabbed page. In many situations, a
web form may be very long, and then you can divide a long form into multiple sub forms.
MultiView control is made up of multiple view controls. You can put multiple ASP.NET controls
inside view controls. One View control is displayed at a time and it is called as the active view.
View control does not work separately. It is always used with a Multiview control.
If working with Visual Studio 2010 or later, you can drag and drop a MultiView control onto the
form. You can drag and drop any number of View controls inside the MultiView control. The
number of view controls is depends upon the need of your application.
MultiView control supports the following important properties
ActiveViewIndex: It is used to determine which view will be active or visible.
Views: It provides the collection of View controls contained in the MultiView control.
For understand the Multiview control, first we will create a user interface as given below.
In the given example, in Multiview control, we have taken three separate View control.
1. In First step we will design to capture Product details
2. In Second step we will design to capture Order details
3. Next we will show summary for confirmation.
Here we have not used any database programming to save the data into the database. We will
show only the confirmation page, that data has been saved.
21
Wizard Control
This control is same as MultiView control but the main difference is that, it has inbuilt navigation
buttons.
The wizard control enables you to design a long form in such a way that you can work in
multiple sub form. You can perform the task in a step by step process. It reduces the work of
developers to design multiple forms. It enables you to create multi step user interface. Wizard
control provides with built-in previous/next functionality.
The Wizard control can contains one or more WizardStep as child controls. Only one
WizardStep is displayed at a time. WizardStep control has an important property called as
StepType. The StepType property determines the type of navigation buttons that will be
displayed for that step. The possible values are:
The StepType associated with each WizardStep determines the type of navigation buttons that
will be displayed for that step. The StepTypes are:
● Start:
● Step:
● Finish:
● Complete:
● Auto:
Important events of Wizard control are as follows:
ActiveStepChanged:
CancelButtonClick:
FinishButtonClick:
NextButtonClick:
PreviousButtonClick:
Now we will create an application as we had done with MultiView control. We will create three
different WizardStep in Wizard control.
1. In First step we will design to capture Product details
2. In Second step we will design to capture Order details
3. Next we will show summary for confirmation.