Unit I -.NET
Unit I -.NET
ASP.NET works on top of the HTTP protocol, and uses the HTTP commands and
policies to set a browser-to-server bilateral communication and cooperation.
The ASP.NET application codes can be written in any of the following languages:
C#
Visual Basic.Net
Jscript
J#
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.
Page state
Session state
The page state is the state of the client, i.e., the content of various input fields in
the web form. The session state is the collective information obtained from various
pages the user visited and worked with, i.e., the overall session state. To clear the
concept, 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.
ASP.NET is a technology, which works on the .Net framework that contains all
web-related functionalities. The .Net framework is made of an object-oriented
hierarchy. An ASP.NET web application is made of pages. When a user requests
an ASP.NET page, the IIS delegates the processing of the page to the ASP.NET
runtime system.
The ASP.NET runtime transforms the .aspx page into an instance of a class, which
inherits from the base class page of the .Net framework. Therefore, each ASP.NET
page is an object and all its components i.e., the server-side controls are also
objects.
DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 2
22UCSCC62 : DOTNET PROGRAMMING UNIT I
.NET Standard is a formal specification of the APIs that are common across .NET
implementations. This allows the same code and libraries to run on different
implementations.
Version compatibility. With rare exceptions, apps that are developed by using
a particular version of .NET Framework run without modification on a later
version.
The two major components of .NET Framework are the Common Language
Runtime and the .NET Framework Class Library.
The Class Library provides a set of APIs and types for common
functionality. It provides types for strings, dates, numbers, etc. The Class
Library includes APIs for reading and writing files, connecting to databases,
drawing, and more.
.NET applications are written in the C#, F#, or Visual Basic programming
language. Code is compiled into a language-agnostic Common Intermediate
Language (CIL). Compiled code is stored in assemblies—files with a .dll or .exe
file extension.
When an app runs, the CLR takes the assembly and uses a just-in-time compiler
(JIT) to turn it into machine code that can execute on the specific architecture of
the computer it is running on.
S.No
. .NET ASP.NET
S.No
. .NET ASP.NET
Language) compiler.
Controls are small building blocks of the graphical user interface, which include
text boxes, buttons, check boxes, list boxes, labels, and numerous other tools.
Using these tools, the users can enter data, make selections and indicate their
preferences.
Controls are also used for structural jobs, like validation, data access, security,
creating master pages, and data manipulation.
HTML controls
HTML Server controls
ASP.NET Server controls
ASP.NET Ajax Server controls
User controls and custom controls
ASP.NET server controls are the primary controls used in ASP.NET. These
controls can be grouped into the following categories:
Validation controls - These are used to validate user input and they work
by running client-side script.
Data source controls - These controls provides data binding to different
data sources.
Data view controls - These are various lists and tables, which can bind to
data from data sources for displaying.
In addition, visual studio has the following features, to help produce in error-free
coding:
ASP.NET server controls with a visual aspect are derived from the WebControl
class and inherit all the properties, events, and methods of this class.
The WebControl class itself and some other server controls that are not visually
rendered are derived from the System.Web.UI.Control class. For example,
PlaceHolder control or XML control.
ASP.Net server controls inherit all properties, events, and methods of the
WebControl and System.Web.UI.Control class.
The following table shows the inherited properties, common to all server controls:
Property Description
AccessKey Pressing this key with the Alt key moves focus to the
control.
Font Font.
TabIndex Gets or sets the tab index of the Web server control.
Method Description
BASIC CONTROLS
Button Controls
When a user clicks a button, two events are raised: Click and Command.
Property Description
The text displayed on the button. This is for button and link
Text
button controls only.
The URL of the page that is requested when the user clicks
PostBackUrl
the button.
Text box controls are typically used to accept input from the user. A text box
control can accept one or more lines of text depending upon the settings of the
TextMode attribute.
Label controls provide an easy way to display text which can be changed from one
execution of a page to the next. If you want to display text that does not change,
you use the literal text.
Property Description
Determines whether the user can change the text in the box;
ReadOnly
default is false, i.e., the user can not change the text.
The mostly used attribute for a label control is 'Text', which implies the text
displayed on the label.
A check box displays a single option that the user can either check or uncheck and
radio buttons present a group of options from which the user can select just one
option.
To create a group of radio buttons, you specify the same name for the GroupName
attribute of each radio button in the group. If more than one group is required in a
single form, then specify a different group name for each group.
If you want check box or radio button to be selected when the form is initially
displayed, set its Checked attribute to true. If the Checked attribute is set to true for
multiple radio buttons in a group, then only the last one is considered as true.
Property Description
Text The text displayed next to the check box or radio button.
List Controls
Drop-down list,
List box,
Radio button list,
Check box list,
Bulleted list.
These control let a user choose from one or more items from the list. List boxes
and drop-down lists contain one or more list items. These lists can be loaded either
by code or by the ListItemCollection editor.
Property Description
Property Description
To work with the items in a drop-down list or list box, you use the Items
property of the control. This property returns a ListItemCollection object
which contains all the items of the list.
The SelectedIndexChanged event is raised when the user selects a different
item from a drop-down list or list box.
The ListItemCollection
When the items into a list box are loaded using strings like:
lstcolor.Items.Add("Blue"), then both the Text and Value properties of the list item
are set to the string value you specify. To set it differently you must create a list
item object and then add that item to the collection.
The ListItemCollection Editor is used to add item to a drop-down list or list box.
This is used to create a static list of items. To display the collection editor, select
edit item from the smart tag menu, or select the control and then click the ellipsis
button from the Item property in the properties window.
Property Description
Methods Description
Adds a new item at the end of the collection and assigns the
Add(string)
string parameter to the Text property of the item.
Remove(string) Removes the item with the text value same as the string.
A radio button list presents a list of mutually exclusive options. A check box list
presents a list of independent options. These controls contain a collection of
ListItem objects that could be referred to through the Items property of the control.
Property Description
The bulleted list control creates bulleted lists or numbered lists. These controls
contain a collection of ListItem objects that could be referred to through the Items
property of the control.
Property Description
HyperLink Control
Property Description
Image Control
The image control is used for displaying images on the web page, or some
alternative text, if the image is not available.
Property Description
ASP.NET Web Pages is a framework that you can use to create dynamic
web pages.
A simple HTML web page is static and its content is determined by the fixed
HTML markup that's in the page, while with dynamic pages you can create
the page content on the fly by using code.
It provides an easy way to combine HTML, CSS, JavaScript and server
code.
With dynamic pages you can do many things like −
Ask a user for making an input by using a form and then change what the
page displays or how it looks.
Take the information from a user, save it in a database, and then list it later.
Send an email from your site.
Interact with other services on the web.
The ASP.NET Web Pages support the ability to run websites side by side. This lets
you to continue to run your older ASP.NET Web Pages applications, build new
ASP.NET Web Pages applications, and run all of them on the same computer.
In this tutorial, we are assuming that you are interested in learning basic
programming.
The ASP.NET Web Pages use C# and Visual Basic programming languages.
In this tutorial, we will use C# as a programming language.
No prior experience in programming required.
DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 27
22UCSCC62 : DOTNET PROGRAMMING UNIT I
If you have ever written any JavaScript in a web page before then it is more
than enough to understand this tutorial.
To start the ASP.NET Web Pages development, you will need the following −
The key development tool for building ASP.NET applications and front ends is
Visual Studio. In this tutorial, we work with Visual Studio 2008.
Installation
Microsoft provides a free version of visual studio which also contains SQL Server
and it can be downloaded from www.visualstudio.com.
Step 1 − Once downloading is complete, run the installer. The following dialog
will be displayed.
Step 2 − Click on the Install button and it will start the installation process.
Step 3 − Once the installation process is completed successfully, you will see the
following dialog. Close this dialog and restart your computer if required.
Step 4 − Open Visual Studio from start Menu which will open the following
dialog. It will be a while for the first time for preparation.
Step 5 − Once all is done you will see the main window of Visual studio.
The new project window allows choosing an application template from the
available templates.
When you start a new web site, ASP.NET provides the starting folders and files for
the site, including two files for the first web form of the site.
The file named Default.aspx contains the HTML and asp code that defines the
form, and the file named Default.aspx.cs (for C# coding) or the file named
Default.aspx.vb (for VB coding) contains the code in the language you have
chosen and this code is responsible for the actions performed on a form.
The primary window in the Visual Studio IDE is the Web Forms Designer
window. Other supporting windows are the Toolbox, the Solution Explorer, and
the Properties window. You use the designer to design a web form, to add code to
the control on the form so that the form works according to your need, you use the
code editor.
To change the Web Forms Designer from one view to another, click on the
Design or source button.
To close a window, click on the close button on the upper right corner and to
redisplay, select it from the View menu.
To hide a window, click on its Auto Hide button. The window then changes
into a tab. To display again, click the Auto Hide button again.
When a new web form is created, Visual Studio automatically generates the
starting HTML for the form and displays it in Source view of the web forms
designer. The Solution Explorer is used to add any other files, folders or any
existing item on the web site.
A typical ASP.NET application consists of many items: the web content files
(.aspx), source files (.cs files), assemblies (.dll and .exe files), data source files
(.mdb files), references, icons, user controls and miscellaneous other files and
folders. All these files that make up the website are contained in a Solution.
DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 34
22UCSCC62 : DOTNET PROGRAMMING UNIT I
When a new website is created. VB2008 automatically creates the solution and
displays it in the solution explorer.
Solutions may contain one or more projects. A project contains content files,
source files, and other files like data sources and image files. Generally, the
contents of a project are compiled into an assembly as an executable file (.exe) or a
dynamic link library (.dll) file.
Selecting Start
Selecting Start Without Debugging from the Debug menu,
pressing F5
Ctrl-F5
The program is built meaning, the .exe or the .dll files are generated by selecting a
command from the Build menu.