0% found this document useful (0 votes)
3 views

Unit I -.NET

Unit I of the document covers the fundamentals of building ASP.NET pages, including the ASP.NET framework, its component model, and the various controls available for web development. It explains how ASP.NET enables the creation of interactive, data-driven web applications and details the architecture of the .NET Framework, which supports multiple programming languages and cross-platform functionality. Additionally, the document outlines the differences between .NET and ASP.NET, and provides an overview of server controls and their properties.

Uploaded by

rogitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit I -.NET

Unit I of the document covers the fundamentals of building ASP.NET pages, including the ASP.NET framework, its component model, and the various controls available for web development. It explains how ASP.NET enables the creation of interactive, data-driven web applications and details the architecture of the .NET Framework, which supports multiple programming languages and cross-platform functionality. Additionally, the document outlines the differences between .NET and ASP.NET, and provides an overview of server controls and their properties.

Uploaded by

rogitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

22UCSCC62 : DOTNET PROGRAMMING UNIT I

Unit I : Building ASP.NET pages


ASP.NET and the .NET framework – understanding ASP.NET controls –
understanding ASP.NET pages – installing the ASP.NET framework.

ASP.NET and the .NET framework

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 set a 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 a stateless protocol. ASP.NET framework helps in storing the


information regarding the state of the application, which consists of:

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 1


22UCSCC62 : DOTNET PROGRAMMING UNIT I

 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.

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.

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

What is .NET Framework?

.NET Framework is a software development framework for building and running


applications on Windows.

.NET and .NET Framework

.NET is a developer platform made up of tools, programming languages, and


libraries for building many different types of applications.

There are various implementations of .NET. Each implementation allows .NET


code to execute in different places—Linux, macOS, Windows, iOS, Android, and
many more.

1. .NET Framework is the original implementation of .NET. It supports


running websites, services, desktop apps, and more on Windows.

2. .NET is a cross-platform implementation for running websites, services, and


console apps on Windows, Linux, and macOS. .NET is open source on
GitHub. .NET was previously called .NET Core.

3. Xamarin/Mono is a .NET implementation for running apps on all the major


mobile operating systems, including iOS and Android.

.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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 3


22UCSCC62 : DOTNET PROGRAMMING UNIT I

.NET Framework is a managed execution environment for Windows that provides


a variety of services to its running apps. It consists of two major components: the
common language runtime (CLR), which is the execution engine that handles
running apps, and the .NET Framework Class Library, which provides a library of
tested, reusable code that developers can call from their own apps. The services
that .NET Framework provides to running apps include the following:

 Memory management. In many programming languages, programmers are


responsible for allocating and releasing memory and for handling object
lifetimes. In .NET Framework apps, the CLR provides these services on
behalf of the app.

 A common type system. In traditional programming languages, basic types


are defined by the compiler, which complicates cross-language
interoperability. In .NET Framework, basic types are defined by the .NET
Framework type system and are common to all languages that target .NET
Framework.

 An extensive class library. Instead of having to write vast amounts of code to


handle common low-level programming operations, programmers use a
readily accessible library of types and their members from the .NET
Framework Class Library.

 Development frameworks and technologies. .NET Framework includes


libraries for specific areas of app development, such as ASP.NET for web
DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 4
22UCSCC62 : DOTNET PROGRAMMING UNIT I

apps, ADO.NET for data access, Windows Communication Foundation for


service-oriented apps, and Windows Presentation Foundation for Windows
desktop apps.

 Language interoperability. Language compilers that target .NET Framework


emit an intermediate code named Common Intermediate Language (CIL),
which, in turn, is compiled at run time by the common language runtime.
With this feature, routines written in one language are accessible to other
languages, and programmers focus on creating apps in their preferred
languages.

 Version compatibility. With rare exceptions, apps that are developed by using
a particular version of .NET Framework run without modification on a later
version.

 Side-by-side execution. .NET Framework helps resolve version conflicts by


allowing multiple versions of the common language runtime to exist on the
same computer. This means that multiple versions of apps can coexist and
that an app can run on the version of .NET Framework with which it was
built. Side-by-side execution applies to the .NET Framework version groups
1.0/1.1, 2.0/3.0/3.5, and 4/4.5.x/4.6.x/4.7.x/4.8.x.

 Multitargeting. By targeting .NET Standard, developers create class libraries


that work on multiple .NET Framework platforms supported by that version
of the standard. For example, libraries that target .NET Standard 2.0 can be
used by apps that target .NET Framework 4.6.1, .NET Core 2.0, and UWP
10.0.16299.

Architecture of .NET Framework

The two major components of .NET Framework are the Common Language
Runtime and the .NET Framework Class Library.

 The Common Language Runtime (CLR) is the execution engine that


handles running applications. It provides services like thread management,
garbage collection, type-safety, exception handling, and more.

 The Class Library provides a set of APIs and types for common
functionality. It provides types for strings, dates, numbers, etc. The Class

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 5


22UCSCC62 : DOTNET PROGRAMMING UNIT I

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.

Difference Between .NET and ASP.NET Framework

S.No
. .NET ASP.NET

.NET is a software development ASP.NET is a main tool that present


framework aimed to develop in the .NET Framework and aimed
1.
Windows, Web and Server based at simplifying the creation of
applications. dynamic webpages.

You can only develop server side


Server side and client side
web applications using ASP.NET as
2. application development can be
it is integrated with .NET
done using .NET framework.
framework.

Mainly used to make business It is used to make dynamic web


3. applications on the Windows pages and websites using .NET
platform. languages.

4. Its programming can be done Its programming can be done using


using any language with CIL any .NET compliant language.
(Common Intermediate

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 6


22UCSCC62 : DOTNET PROGRAMMING UNIT I

S.No
. .NET ASP.NET

Language) compiler.

Understanding ASP.NET Controls


ASP.NET controls are the heart of ASP.NET Framework. An ASP.NET control is
a .NET class that executes on the server and renders certain content to the browser.
For example, in the first ASP.NET page created at the beginning of this chapter, a
Label control was used to display the current date and time. The ASP.NET
framework includes more than 90 controls, which enable you to do everything
from displaying a list of database records to displaying a randomly rotating banner
advertisement.

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.

ASP.NET uses five types of web controls, which are:

 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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 7


22UCSCC62 : DOTNET PROGRAMMING UNIT I

 Personalization controls - These are used for personalization of a page


according to the user preferences, based on user information.
 Login and security controls - These controls provide user authentication.
 Master pages - These controls provide consistent layout and interface
throughout the application.
 Navigation controls - These controls help in navigation. For example,
menus, tree view etc.
 Rich controls - These controls implement special features. For example,
AdRotator, FileUpload, and Calendar control.

The syntax for using server controls is:

<asp:controlType ID ="ControlID" runat="server" Property1=value1


[Property2=value2] />

In addition, visual studio has the following features, to help produce in error-free
coding:

 Dragging and dropping of controls in design view


 IntelliSense feature that displays and auto-completes the properties
 The properties window to set the property values directly

Properties of the Server Controls

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

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 8


22UCSCC62 : DOTNET PROGRAMMING UNIT I

control.

It is the collection of arbitrary attributes (for rendering


Attributes
only) that do not correspond to properties on the control.

BackColor Background color.

BindingContainer The control that contains this control's data binding.

BorderColor Border color.

BorderStyle Border style.

BorderWidth Border width.

CausesValidation Indicates if it causes validation.

It indicates whether the server control's child controls


ChildControlCreated
have been created.

ClientID Control ID for HTML markup.

The HttpContext object associated with the server


Context
control.

Controls Collection of all controls contained within the control.

ControlStyle The style of the Web server control.

CssClass CSS class

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 9


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Gets a reference to the naming container if the naming


DataItemContainer
container implements IDataItemContainer.

Gets a reference to the naming container if the naming


DataKeysContainer
container implements IDataKeysControl.

It indicates whether the control is being used on a design


DesignMode
surface.

Gets or sets the CSS class to apply to the rendered


DisabledCssClass
HTML element when the control is disabled.

Enabled Indicates whether the control is grayed out.

EnableTheming Indicates whether theming applies to the control.

Indicates whether the view state of the control is


EnableViewState
maintained.

Events Gets a list of event handler delegates for the control.

Font Font.

Forecolor Foreground color.

HasAttributes Indicates whether the control has attributes set.

Indicates whether the current server control's child


HasChildViewState
controls have any saved view-state settings.

Height Height in pixels or %.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 10


22UCSCC62 : DOTNET PROGRAMMING UNIT I

ID Identifier for the control.

IsChildControlStateCleare Indicates whether controls contained within this control


d have control state.

IsEnabled Gets a value indicating whether the control is enabled.

It indicates whether the server control is saving changes


IsTrackingViewState
to its view state.

IsViewStateEnabled It indicates whether view state is enabled for this control.

It indicates whether the control participates in loading its


LoadViewStateById
view state by ID instead of index.

Page Page containing the control.

Parent Parent control.

It specifies the ASP.NET version that the rendered


RenderingCompatibility
HTML will be compatible with.

The container that hosts the current control when


Site
rendered on a design surface.

SkinID Gets or sets the skin to apply to the control.

Gets a collection of text attributes that will be rendered as


Style a style attribute on the outer tag of the Web server
control.

TabIndex Gets or sets the tab index of the Web server control.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 11


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Gets the HtmlTextWriterTag value that corresponds to


TagKey
this Web server control.

TagName Gets the name of the control tag.

TemplateControl The template that contains this control.

Gets the virtual directory of the page or control


TemplateSourceDirectory
containing this control.

Gets or sets the text displayed when the mouse pointer


ToolTip
hovers over the web server control.

UniqueID Unique identifier.

Gets a dictionary of state information that saves and


ViewState restores the view state of a server control across multiple
requests for the same page.

It indicates whether the StateBag object is case-


ViewStateIgnoreCase
insensitive.

ViewStateMode Gets or sets the view-state mode of this control.

Visible It indicates whether a server control is visible.

Width Gets or sets the width of the Web server control.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 12


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Methods of the Server Controls

The following table provides the methods of the server controls:

Method Description

Adds HTML attributes and styles that need to be


AddAttributesToRender
rendered to the specified HtmlTextWriterTag.

Called after a child control is added to the Controls


AddedControl
collection of the control object.

Notifies the server control that an element, either


AddParsedSubObject XML or HTML, was parsed, and adds the element
to the server control's control collection.

Applies the style properties defined in the page style


ApplyStyleSheetSkin
sheet to the control.

Infrastructure. Sets the cached ClientID value to


ClearCachedClientID
null.

Deletes the control-state information for the server


ClearChildControlState
control's child controls.

Deletes the view-state and control-state information


ClearChildState
for all the server control's child controls.

Deletes the view-state information for all the server


ClearChildViewState
control's child controls.

CreateChildControls Used in creating child controls.

Creates a new ControlCollection object to hold the


CreateControlCollection
child controls.

Creates the style object that is used to implement all


CreateControlStyle
style related properties.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 13


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Binds a data source to the server control and all its


DataBind
child controls.

Binds a data source to the server control and all its


DataBind(Boolean) child controls with an option to raise the
DataBinding event.

Binds a data source to the server control's child


DataBindChildren
controls.

Enables a server control to perform final clean up


Dispose
before it is released from memory.

Determines whether the server control contains child


EnsureChildControls
controls. If it does not, it creates child controls.

Creates an identifier for controls that do not have an


EnsureID
identifier.

Determines whether the specified object is equal to


Equals(Object)
the current object.

Allows an object to attempt to free resources and


Finalize perform other cleanup operations before the object
is reclaimed by garbage collection.

Searches the current naming container for a server


FindControl(String)
control with the specified id parameter.

Searches the current naming container for a server


FindControl(String, Int32)
control with the specified id and an integer.

Focus Sets input focus to a control.

GetDesignModeState Gets design-time data for a control.

GetType Gets the type of the current instance.

GetUniqueIDRelativeTo Returns the prefixed portion of the UniqueID

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 14


22UCSCC62 : DOTNET PROGRAMMING UNIT I

property of the specified control.

Determines if the server control contains any child


HasControls
controls.

Indicates whether events are registered for the


HasEvents
control or any child controls.

Determines if the server control holds only literal


IsLiteralContent
content.

LoadControlState Restores control-state information.

LoadViewState Restores view-state information.

Retrieves the physical path that a virtual path, either


MapPathSecure
absolute or relative, maps to.

MemberwiseClone Creates a shallow copy of the current object.

Copies any nonblank elements of the specified style


MergeStyle to the web control, but does not overwrite any
existing style elements of the control.

Determines whether the event for the server control


OnBubbleEvent
is passed up the page's UI server control hierarchy.

OnDataBinding Raises the data binding event.

OnInit Raises the Init event.

OnLoad Raises the Load event.

OnPreRender Raises the PreRender event.

OnUnload Raises the Unload event.

OpenFile Gets a Stream used to read a file.

RemovedControl Called after a child control is removed from the

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 15


22UCSCC62 : DOTNET PROGRAMMING UNIT I

controls collection of the control object.

Render Renders the control to the specified HTML writer.

Renders the HTML opening tag of the control to the


RenderBeginTag
specified writer.

Outputs the contents of a server control's children to


RenderChildren a provided HtmlTextWriter object, which writes the
contents to be rendered on the client.

Renders the contents of the control to the specified


RenderContents
writer.

Outputs server control content to a provided


RenderControl(HtmlTextWriter
HtmlTextWriter object and stores tracing
)
information about the control if tracing is enabled.

Renders the HTML closing tag of the control into


RenderEndTag
the specified writer.

Gets the control adapter responsible for rendering


ResolveAdapter
the specified control.

Saves any server control state changes that have


SaveControlState occurred since the time the page was posted back to
the server.

Saves any state that was modified after the


SaveViewState
TrackViewState method was invoked.

SetDesignModeState Sets design-time data for a control.

ToString Returns a string that represents the current object.

Causes the control to track changes to its view state


TrackViewState so that they can be stored in the object's view state
property.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 16


22UCSCC62 : DOTNET PROGRAMMING UNIT I

BASIC CONTROLS

The basic controls available in ASP.NET.

Button Controls

ASP.NET provides three types of button control:

 Button : It displays text within a rectangular area.


 Link Button : It displays text that looks like a hyperlink.
 Image Button : It displays an image.

When a user clicks a button, two events are raised: Click and Command.

Basic syntax of button control:

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click"


/>

Common properties of the button control:

Property Description

The text displayed on the button. This is for button and link
Text
button controls only.

For image button control only. The image to be displayed


ImageUrl
for the button.

For image button control only. The text to be displayed if


AlternateText
the browser cannot display the image.

Determines whether page validation occurs when a user


CausesValidation
clicks the button. The default is true.

CommandName A string value that is passed to the command event when a

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 17


22UCSCC62 : DOTNET PROGRAMMING UNIT I

user clicks the button.

A string value that is passed to the command event when a


CommandArgument
user clicks the button.

The URL of the page that is requested when the user clicks
PostBackUrl
the button.

Text Boxes and Labels

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.

Basic syntax of text control:

<asp:TextBox ID="txtstate" runat="server" ></asp:TextBox>

Common Properties of the Text Box and Labels:

Property Description

Specifies the type of text box. SingleLine creates a standard


text box, MultiLIne creates a text box that accepts more than
TextMode
one line of text and the Password causes the characters that
are entered to be masked. The default is SingleLine.

Text The text content of the text box.

MaxLength The maximum number of characters that can be entered into

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 18


22UCSCC62 : DOTNET PROGRAMMING UNIT I

the text box.

It determines whether or not text wraps automatically for


Wrap
multi-line text box; default is true.

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 width of the text box in characters. The actual width is


Columns
determined based on the font that is used for the text entry.

The height of a multi-line text box in lines. The default


Rows
value is 0, means a single line text box.

The mostly used attribute for a label control is 'Text', which implies the text
displayed on the label.

Check Boxes and Radio Buttons

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.

Basic syntax of check box:

<asp:CheckBox ID= "chkoption" runat= "Server">


</asp:CheckBox>

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 19


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Basic syntax of radio button:

<asp:RadioButton ID= "rdboption" runat= "Server">


</asp: RadioButton>

Common properties of check boxes and radio buttons:

Property Description

Text The text displayed next to the check box or radio button.

Checked Specifies whether it is selected or not, default is false.

GroupName Name of the group the control belongs to.

List Controls

ASP.NET provides the following 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.

Basic syntax of list box control:

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"


OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
</asp:ListBox>

Basic syntax of drop-down list control:

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 20


22UCSCC62 : DOTNET PROGRAMMING UNIT I

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"


OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

Common properties of list box and drop-down Lists:

Property Description

The collection of ListItem objects that represents the items


Items in the control. This property returns an object of type
ListItemCollection.

Specifies the number of items displayed in the box. If actual


Rows list contains more rows than displayed then a scroll bar is
added.

The index of the currently selected item. If more than one


SelectedIndex item is selected, then the index of the first selected item. If
no item is selected, the value of this property is -1.

The value of the currently selected item. If more than one


item is selected, then the value of the first selected item. If
SelectedValue
no item is selected, the value of this property is an empty
string ("").

Indicates whether a list box allows single selections or


SelectionMode
multiple selections.

Common properties of each list item objects:

Property Description

Text The text displayed for the item.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 21


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Selected Indicates whether the item is selected.

Value A string value associated with the item.

It is important to notes that:

 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

The ListItemCollection object is a collection of ListItem objects. Each ListItem


object represents one item in the list. Items in a ListItemCollection are numbered
from 0.

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.

Common properties of ListItemCollection:

Property Description

A ListItem object that represents the item at the specified


Item(integer)
index.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 22


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Count The number of items in the collection.

Common methods of ListItemCollection:

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.

Add(ListItem) Adds a new item at the end of the collection.

Inserts an item at the specified index location in the


Insert(integer, string) collection, and assigns string parameter to the text property
of the item.

Inserts the item at the specified index location in the


Insert(integer, ListItem)
collection.

Remove(string) Removes the item with the text value same as the string.

Remove(ListItem) Removes the specified item.

RemoveAt(integer) Removes the item at the specified index as the integer.

Clear Removes all the items of the collection.

FindByValue(string) Returns the item whose value is same as the string.

FindByValue(Text) Returns the item whose text is same as the string.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 23


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Radio Button list and Check Box list

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.

Basic syntax of radio button list:

<asp:RadioButtonList ID="RadioButtonList1" runat="server"


AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>

Basic syntax of check box list:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"


OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>

Common properties of check box and radio button lists:

Property Description

This attribute specifies whether the table tags or the normal


RepeatLayout html flow to use while formatting the list when it is
rendered. The default is Table.

It specifies the direction in which the controls to be


RepeatDirection repeated. The values available are Horizontal and Vertical.
Default is Vertical.

It specifies the number of columns to use when repeating the


RepeatColumns
controls; default is 0.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 24


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Bulleted lists and Numbered lists

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.

Basic syntax of a bulleted list:

<asp:BulletedList ID="BulletedList1" runat="server">


</asp:BulletedList>

Common properties of the bulleted list:

Property Description

This property specifies the style and looks of the bullets, or


BulletStyle
numbers.

It specifies the direction in which the controls to be


RepeatDirection repeated. The values available are Horizontal and Vertical.
Default is Vertical.

It specifies the number of columns to use when repeating the


RepeatColumns
controls; default is 0.

HyperLink Control

The HyperLink control is like the HTML <a> element.

Basic syntax for a hyperlink control:

<asp:HyperLink ID="HyperLink1" runat="server">


HyperLink
</asp:HyperLink>

It has the following important properties:

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 25


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Property Description

ImageUrl Path of the image to be displayed by the control.

NavigateUrl Target link URL.

Text The text to be displayed as the link.

Target The window or frame which loads the linked page.

Image Control

The image control is used for displaying images on the web page, or some
alternative text, if the image is not available.

Basic syntax for an image control:

<asp:Image ID="Image1" runat="server">

It has the following important properties:

Property Description

AlternateText Alternate text to be displayed in absence of the image.

ImageAlign Alignment options for the control.

ImageUrl Path of the image to be displayed by the control.

What is ASP.NET Web Pages?


ASP.NET Web Pages is a simplified framework that we can use to build ASP.NET
content quickly and easily. It is one of the three programming models for creating
ASP.NET web sites and web applications. The other two programming models
are Web Forms and MVC.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 26


22UCSCC62 : DOTNET PROGRAMMING UNIT I

 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.

What Should You Know?

 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.

What Do You Need?

To start the ASP.NET Web Pages development, you will need the following −

 A computer/laptop that is running Windows 10, Windows 8, Windows 7,


Windows Server 2008, or Windows Server 2012.
 A live internet connection.
 Administrator privileges which is required just for the installation.

ASP.NET provides an abstraction layer on top of HTTP on which the web


applications are built. It provides high-level entities such as classes and
components within an object-oriented paradigm.

The key development tool for building ASP.NET applications and front ends is
Visual Studio. In this tutorial, we work with Visual Studio 2008.

Visual Studio is an integrated development environment for writing, compiling,


and debugging the code. It provides a complete set of development tools for
building ASP.NET web applications, web services, desktop applications, and
mobile applications.

Installing the ASP.NET framework

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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 28


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Step 2 − Click on the Install button and it will start the installation process.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 29


22UCSCC62 : DOTNET PROGRAMMING UNIT I

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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 30


22UCSCC62 : DOTNET PROGRAMMING UNIT I

Let’s create a new project from File → New → Project

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 31


22UCSCC62 : DOTNET PROGRAMMING UNIT I

The Visual Studio IDE

The new project window allows choosing an application template from the
available templates.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 32


22UCSCC62 : DOTNET PROGRAMMING UNIT I

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.

Working with Views and Windows

You can work with windows in the following ways:

 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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 33


22UCSCC62 : DOTNET PROGRAMMING UNIT I

 To change the size of a window, just drag it.

Adding Folders and Files to your Website

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.

 To add a standard folder, right-click on the project or folder under which


you are going to add the folder in the Solution Explorer and choose New
Folder.
 To add an ASP.NET folder, right-click on the project in the Solution
Explorer and select the folder from the list.
 To add an existing item to the site, right-click on the project or folder under
which you are going to add the item in the Solution Explorer and select from
the dialog box.

Projects and Solutions

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.

Typically a project contains the following content files:

 Page file (.aspx)


 User control (.ascx)
 Web service (.asmx)
 Master page (.master)
 Site map (.sitemap)
 Website configuration file (.config)

Building and Running a Project

You can execute an application by:

 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.

DEPARTMENT OF COMPUTER SCIENCE- MRS.R.SUGANYA AP /RASC Page 35

You might also like