Professional Documents
Culture Documents
Visual Programming Classroom
Visual Programming Classroom
Visual Studio_CSS 7
Life Cycle 19
Introduction 29
First Example 55
Environment 77
ASP.NET Web Forms Server Controls 96
ASP.NET Models 131
ASP.NET Event Handling 138
Mod2-Validation Controls 150
Intro. to Validation controls 186
StateManagement-Part1 205
StateManagement-Part2 214
StateManagement-Part3 251
validation 282
ADO.Net 286
Data Source Controls and Data Controls 319
DataListView controls 352
Membership 376
Login Controls 407
Visual Programming
BCA S5
Syllabus
▪ An Introduction to ASP.NET web
programming – An introduction to
web programming, an introduction
to ASP.NET application development,
quick preview of how an ASP.NET
application works.
▪ Visual Studio features for working
Module 1 with CSS.
▪ Introduction to server controls, how
to work with button controls, text
boxes, labels, check boxes, radio
button, list controls, and other web
server controls like image, hyperlink,
file upload, and calendar controls.
▪Introduction to validation
controls, basic validation
controls, validation techniques
and advanced validation
controls.
Module 2 ▪How to manage state – how to
use view state, session state
and application state.
▪How to use cookies.
▪An introduction to database
programming – Introduction to
relational database, how to use
SQL to work with data in
database.
▪Introduction to ADO.NET 4.
Module 3 How to use SQL data source,
how to use custom statements
and stored procedures, Data list
controls, Data binding,
advanced features of a SQL data
source.
▪ Customise the GridView control,
Update GridView data, DataListView
controls, FormView Control, ListView
control and update ListView data.
▪ Introduction to SSL, how to get and
use digital source certificate, how to
Module 4
use a secure connection, Introduction
to authentication, how to setup
authentication and authorization,
how to use login controls, how to
configure ASP.NET application, how
to deploy an ASP.NET application.
ASP.NET PROGRAMMING
Module 1
WHAT IS CSS?
Cascading Style Sheet
Stylesheet Language
Standards-based set of properties and attributes to define
styles
To describe the presentation a document written in a
‘markup language’ like HTML or XML
Markup encoding: <p>My paragraph here.</p>
Defines the style of how things in <p> tags appear.
Font, color, size, margins, etc.
Cascading
Rules to determine how to apply markup that contains other
markup
CONTINUE….
Separate Content from Form
⚫ Content is the text and images, marked up to define regions of
specific types
⚫ Form defines the “style” for the content
<font size=“14px”>
My First Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
The old My information 1 goes here.
</font>
way: <font size=“14px”>
My Second Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
Different information goes here.
</font>
CONTINUE….
Separate Content from Form
⚫ Content
<p class=“header”>My First Header</p>
<p class=“info”>My Information 1 goes here</p>
<p class=“header”>My Second Header</p>
<p class=“info”>Different Information goes here</p>
(Specific markup properties like Class will be discussed later).
⚫ Form or Style
.header { font-size:14px;}
.info { font-family: verdana;
font-color: blue;
font-size: 12px; }
CONTINUE….
Separate Content from Form
⚫ Specify the style once for every instance of that
class.
Example: Specify the font once for all text on the
HTML page that you’ve identified as a “header”.
skin1.css
.info { background-color: White;
font-family: Verdana;
font-color: Blue; }
skin2.css
.info { background-color: Blue;
font-family: Serif;
font-color: White; }
<p>Content</p>
<p class=“myinfo”>Content</p>
<div class=“myinfo1”>Other content</div>
CASCADING INHERITANCE
Nested elements inherit
the properties from the
its parent
Cons
⚫ Different browsers may interpret Style Sheets in
different ways
⚫ Some styles may not be seen at all on some
browsers
ASP.NET
Module I
ASP.NET Life Cycle
ASP.NET life cycle specifies, how:
• ASP.NET processes pages to produce dynamic
output
• The application and its pages are instantiated
and processed
• ASP.NET compiles the pages dynamically
The ASP.NET life cycle could be divided into two
groups:
• Application Life Cycle
• Page Life Cycle
ASP.NET Application Life
Cycle
The application life cycle has the following stages:
• User makes a request for accessing application
resource, a page. Browser sends this request to the
web server.
• A unified pipeline receives the first request and the
following events take place:
• An object of the class ApplicationManager is
created.
• An object of the class HostingEnvironment is
created to provide information regarding the
resources.
• Top level items in the application are compiled.
Continue….
• Response objects are created. The application
objects such as HttpContext, HttpRequest and
HttpResponse are created and initialized.
• An instance of the HttpApplication object is
created and assigned to the request.
• The request is processed by the HttpApplication
class. Different events are raised by this class for
processing the request.
ASP.NET Page Lifecycle
• In ASP.NET, a web page has execution lifecycle that
includes various phases. These phases include
initialization, instantiation, restoring and
maintaining state etc. it is required to understand
the page lifecycle so that we can put custom code
at any stage to perform our business logic.
Page Lifecycle stages
The following table contains the lifecycle stages of
ASP.NET web page.
Stage Description
Page request This stage occurs before the lifecycle begins.
When a page is requested by the user,
ASP.NET parses and compiles that page.
Start In this stage, page properties such as Request
and response are set. It also determines the
Request type.
Initialization In this stage, each control's UniqueID property
is set. Master page is applied to the page.
1) PHP
2) C++
3) Java and JSP
4) Python
5) Ruby on Rails
Client-side Programming
• It is the program that runs on the client machine
(browser) and deals with the user interface/display
and any other processing that can happen on client
machine like reading/writing cookies.
1) Interact with temporary storage
2) Make interactive web pages
3) Interact with local storage
4) Sending request for data to server
5) Send request to server
6) work as an interface between server and user
Continue….
The Programming languages for client-side
programming are :
1) JavaScript
2) VBScript
3) HTML
4) CSS
5) AJAX
Continue….
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 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.
Continue….
• 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.
Continue….
• It is used to develop websites, web applications
and web services. It provides fantastic integration
of HTML, CSS and JavaScript. It was first released in
January 2002. It is built on the Common Language
Runtime (CLR) and allows programmers to write
code using any supported .NET language.
• ASP.NET provides three development styles for
creating web applications:
• Web Forms
• ASP.NET MVC
• ASP.NET Web Pages
Continue….
Web Forms
• It is an event driven development framework. It is used
to develop application with powerful data access. It
provides server side controls and events to create web
application. It is part of the ASP.NET framework.
ASP.NET MVC
• It gives us a MVC (Model View Controller),
patterns-based way to build dynamic websites. It
enables a clean separation of concerns and that gives
you full control over markup for enjoyable, agile
development. It also provides many features that
enable fast development for creating outstanding
applications.
Continue….
ASP.NET Web Pages
• It is used to create dynamic web pages. It provides
fast and lightweight way to combine server code
with HTML. It helps to add video, link to the social
sites. It also provides other features like you can
create beautiful sites that conform to the latest
web standards.
Continue….
ASP.NET PROGRAMMING
Module I
Introduction
⚫ An ASP.NET page is made up of a number of server
controls along with HTML controls, text, and images.
Sensitive data from the page and the states of different
controls on the page are stored in hidden fields that
form the context of that page request.
⚫ An ASP.NET page is also a server side file saved with
the .aspx extension. It is modular in nature and can be
divided into the following core sections:
⚫ Page Directives
⚫ Code Section
⚫ Page Layout
Page Directives
⚫ The page directives set up the environment for the
page to run. The @Page directive defines
page-specific attributes used by ASP.NET page
parser and compiler. Page directives specify how
the page should be processed, and which
assumptions need to be taken about the page.
⚫ It allows importing namespaces, loading
assemblies, and registering new controls with
custom tag names and namespace prefixes.
Code Section
⚫ The code section provides the handlers for the page
and control events along with other functions
required. We mentioned that, ASP.NET follows an
object model. Now, these objects raise events when
some events take place on the user interface, like a user
clicks a button or moves the cursor. The kind of
response these events need to reciprocate is coded in
the event handler functions. The event handlers are
nothing but functions bound to the controls.
⚫ The code section or the code behind file provides all
these event handler routines, and other functions used
by the developer. The page code could be precompiled
and deployed in the form of a binary assembly.
Page Layout
⚫ The page layout provides the interface of the page. It
contains the server controls, text, inline JavaScript, and
HTML tags.
⚫ The following code snippet provides a sample
ASP.NET page explaining Page directives, code section
and page layout written in C#:
Example
<!-- directives -->
<% @Page Language="C#" %>
Module I
ASP.NET Web Forms Server Controls
• ASP.NET provides web forms controls that are used
to create HTML components.
• These controls are categories as server and client
based.
• The following table contains the server controls for
the web forms.
Control Name Applicable Events Description
Property Description
< asp:HyperLinkID="HyperLink1" runat="server"
Text="JavaTpoint" NavigateUrl="www.javatpoint.com"
>
</asp:HyperLink>
Continue….
Property Description
< asp:RadioButtonID="RadioButton1" runat="server"
Text="Male" GroupName="gender"/>
Continue….
Property Description
AccessKey It is used to set keyboard shortcut for the
control.
TabIndex The tab order of the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
BorderWidth It is used to set width of border of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the
control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.
ASP.NET Web Forms Calendar
• It is used to display selectable date in a
calendar. It also shows data associated with
specific date. This control displays a calendar
through which users can move to any day in
any year.
• We can also set Selected Date property that
shows specified date in the calendar.
• To create Calendar we can drag it from the
toolbox of visual studio.
< asp:CalendarID="Calendar1" runat="server"
SelectedDate="2017-06-15" > </asp:Calendar>
Continue…
Property Description
AccessKey It is used to set keyboard shortcut for the
control.
TabIndex The tab order of the control.
BackColor It is used to set background color of the control.
< asp:CheckBox ID="CheckBox2" runat="server"
Text="J2EE"/>
Continue…
Property Description
AccessKey It is used to set keyboard shortcut for the control.
TabIndex The tab order of the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
BorderWidth It is used to set width of border of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.
Checked It is used to set check state of the control either true or
false.
ASP.NET LinkButton
• It is a server web control that acts as a hyperlink. It is
used to display a hyperlink-style button control on the
web page. ASP.NET provides a tag to create
LinkButton and has following syntax.
<asp:LinkButton ID="LinkButton1" runat="server" >
javapoint</asp:LinkButton>
ASP.NET Web Forms FileUpload
• It is an input controller which is used to upload file to
the server. It creates a browse button on the form
that pop up a window to select the file from the
local machine.
• To implement FileUpload we can drag it from the
toolbox in visual studio.
< asp:FileUpload ID="FileUpload1" runat="server"/>
Property Description
<asp:ListItem value="value" selected="True|False">
Text
</asp:ListItem>
</asp:DropDownList>
ASP.NET DataList
• The ASP.NET DataList control is a light weight
server side control that works as a container
for data items.
• It is used to display data into a list format to
the web pages.
• It displays data from the data source.
• The data source can be either a DataTable
or a table from database.
ASP.NET DataGrid
• .NET Framework provides DataGrid control
to display data on the web page.
• It was introduced in .NET 1.0 and now has
been deprecated.
• DataGrid is used to display data in scrollable
grid.
• It requires data source to populate data in
the grid.
• It is a server side control and can be
dragged from the toolbox to the web form.
• Data Source for the DataGrid can be either
a DataTable or a database.
ASP.NET
Module I
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.
Continue…. Page State VS Session State
Module I
ASP.NET - Event Handling
⚫ An event is an action or occurrence such as
a mouse click, a key press, mouse
movements, or any system-generated
notification.
⚫ A process communicates through events.
For example, interrupts are
system-generated events.
⚫ When events occur, the application should
be able to respond to it and manage it.
Continue…
⚫ Events in ASP.NET raised at the client machine,
and handled at the server machine. For
example, a user clicks a button displayed in the
browser. A Click event is raised. The browser
handles this client-side event by posting it to
the server.
⚫ The server has a subroutine describing what to
do when the event is raised; it is called the
event-handler. Therefore, when the event
message is transmitted to the server, it checks
whether the Click event has an associated
event handler. If it has, the event handler is
executed.
Event Arguments
⚫ ASP.NET event handlers generally take two
parameters and return void. The first
parameter represents the object raising the
event and the second parameter is event
argument.
⚫ The general syntax of an event is:
private void EventName (object sender,
EventArgs e);
Application and Session Events
The most important application events are:
⚫ Application_Start - It is raised when the
application/website is started.
⚫ Application_End - It is raised when the
application/website is stopped.
Similarly, the most used Session events are:
⚫ Session_Start - It is raised when a user
first requests a page from the application.
⚫ Session_End - It is raised when the
session ends.
Page and Control Events
Common page and control events are:
⚫ DataBinding - It is raised when a control binds to
a data source.
⚫ Disposed - It is raised when the page or the
control is released.
⚫ Error - It is a page event, occurs when an
unhandled exception is thrown.
⚫ Init - It is raised when the page or the control is
initialized.
⚫ Load - It is raised when the page or a control is
loaded.
⚫ PreRender - It is raised when the page or the
control is to be rendered.
⚫ Unload - It is raised when the page or control is
unloaded from memory.
Event Handling Using Controls
⚫ All ASP.NET controls are implemented as
classes, and they have events which are fired
when a user performs a certain action on
them. For example, when a user clicks a
button the 'Click' event is generated.
⚫ For handling events, there are in-built
attributes and event handlers. Event handler
is coded to respond to an event, and take
appropriate action on it.
Continue…
The common control events are:
Event Attribute Controls
HyperLink Click
ImageButton Click
ImageMap Click
LinkButton Click
ListBox SelectedIndexChanged
Menu MenuItemClick
RadioButton CheckedChanged
RadioButtonList SelectedIndexChanged
Module 2
Validation Controls
Validation
• Validation or data validation means checking or verifying any data
that comes into the computer.
• Data validation is a method for checking the accuracy and quality of
your data, typically performed prior to importing and processing.
Why Validation??
1. Users might ignore an important field and leave it blank.
2. Users might try to type a short string of nonsense to circumvent a
required field check.
3. Users might make an honest mistake, such as entering a typing
error, entering a nonnumeric character in a number field, or
submitting the wrong type of information.
4. Malicious users might try to exploit a weakness in your code by
entering carefully structured wrong values. For example, they might
attempt to cause a specific error that will reveal sensitive
information
Validation
• When you enter data, the browser and/or the web server will check
to see that the data is in the correct format and within the constraints
set by the application. Validation done in the browser is
called client-side validation, while validation done on the server is
called server-side validation.
• If the information is correctly formatted, the application allows the
data to be submitted to the server and (usually) saved in a database;
if the information isn't correctly formatted, it gives the user an error
message explaining what needs to be corrected, and lets them try
again.
Types of validation
• Validation can be classified into two types based on client and server
validation:
• Client side Validation
• Validations performed at Client-Side i.e., browser.
• User gets information immediately as validation performed before a request
is sent to the server.
• Server side Validation
• Server-side validation takes place before data processing in the database.
• This type of validation is used, where client browser dependencies are
involved.
ASP.Net Validation Controls
• ASP.Net also allows the freedom of writing your own validator. This
eases the task of a developer to validate the form at the client side
itself. It also allows putting more complex validations in place.
Validations that are business or application-specific can be written
using custom validators.
• The custom validation code is written in a function in the code-behind
page and the function name is passed as an attribute to the
CustomValidator class. Custom validation can be done either at the
client-side or the server-side.
Custom Validator
• ClientValidationFunction property specifies that the validation is to be
performed on the client-side. Such validation code must be written in
some scripting language such as JavaScript, VBScript, etc.
• The ServerValidate event handler is used when validation has to be
done on the server-side. The server-side validation routine is written
in C#, VB .Net or any other .Net language
• CustomValidator allows you to perform validation from both the
client-side as well as server-side.
Syntax
Custom validation on the client
RequiredFieldValidator
• RangeValidator
• CompareValidator
• RegularExpressionValidator
• CustomValidator
• ValidationSummary
ToolBox
Thank You
Validation Controls
Module II
Introduction to Validation Controls
⚫ Validation is important part of any
web application. User's input must
always be validated before sending
across different layers of the
application.
⚫ Validation controls are used to,
⚫ Implement presentation logic.
⚫ To validate user input data.
⚫ Data format, data type and data
range is used for validation.
Continue….
⚫ Validation is of two types
⚫ Client Side
⚫ Serve Side
⚫ Client side validation is good but we have to
be dependent on browser and scripting
language support.
• View State is the method to preserve the Value of the Page and
Controls between round trips. It is a Page-Level State Management
technique.
View State – Advantages
• Advantages
• Easy to Implement.
• No server resources are required: The View State is contained in a structure
within the page load.
• Enhanced security features: It can be encoded and compressed or Unicode
implementation.
Disadvantages of View State
• Security Risk: The Information of View State can be seen in the page output
source directly. You can manually encrypt and decrypt the contents of a
Hidden Field, but It requires extra coding. If security is a concern then
consider using a Server-Based state Mechanism so that no sensitive
information is sent to the client.
• Performance: Performance is not good if we use a large amount of data
because View State is stored in the page itself and storing a large value can
cause the page to be slow.
• Device limitation: Mobile Devices might not have the memory capacity to
store a large amount of View State data.
• It can store values for the same page only.
When We Should Use View State
• When the data to be stored is small.
• Try to avoid secure data.
How to Enable and Disable View State
• You can enable and disable View State for a single control as well as at the
page level also. To turn off View State for a single control, set the
EnableViewState property of that control to false.
• TextBox1.EnableViewState=false;
• To turn off the View State for an entire page, we need to
set EnableViewState to false of the page directive as shown below:
http://www.localhost.com/Webform2.aspx?name=ABC&lastName=X
YZ
This HTML address uses a QueryString property to pass values
between pages.
Query Strings
• A query string is a collection of characters input to a computer or web
browser.
• A Query String is helpful when we want to transfer a value from one
page to another. When we need to pass content between the HTML
pages or aspx Web Forms in the context of ASP.NET, a Query String is
very easy to use and the Query String follows a separating character,
usually a Question Mark (?).
Query Strings
• A query string consists of two parts, field and value, and each of pair separated by ampersand (&).
•
• The ?(question mark in a query string indicates the beginning of a query string and it's value.
•
• There is a limit on the Query string length. Hence, Query strings cannot be used to send very long
data.
•
• Query strings are visible to the user, hence should not be used to send sensitive information such as
a username and password, unless encrypted.
•
• To retrieve the query string value, use Request object's QueryString property.
• For sending information to other page Response.Redirect() method used and for retrieve
information from url use Request.QueryString() method used.
Cookies
• Cookie is a small text file which is created by the client's browser and
also stored on the client hard disk by the browser.
• It does not use server memory. Generally a cookie is used to identify
users.
Cookies
• A cookie is a small file that stores user information.
• Whenever a user makes a request for a page the first time, the server
creates a cookie and sends it to the client along with the requested
page and the client browser receives that cookie and stores it on the
client machine either permanently or temporarily (persistent or non
persistence).
• The next time the user makes a request for the same site, either the
same or another page, the browser checks the existence of the cookie
for that site in the folder.
• If the cookie exists it sends a request with the same cookie, else that
request is treated as a new request.
Cookies
• Cookies are always sent with the request to the web server and
information can be retrieved from the cookies at the web server.
Every time a user visits a website, cookies are retrieved from the user
machine and help identify the user.
• 1. Persistence Cookie: Cookies which you can set an expiry date time
are called persistence cookies. Persistence cookies are permanently
stored till the time you set.
• 2. Non-Persistence Cookie: Non persistence cookies are not
permanently stored on the user client hard disk folder. It maintains
user information as long as the user accesses the same browser.
When user closes the browser the cookie will be discarded. Non
Persistence cookies are useful for public computers.
Limitations
• The number of cookies allowed is limited and varies according to the
browser.
• Most browsers allow 20 cookies per server in a client's hard disk
folder and the size of a cookie is not more than 4096 bytes or 4 KB of
data that also includes name and value data.
Code – Persistent Cookies
Code- Non – Persistence Cookies
State Management
Part 3 – Session State
Server Side State Management Techniques
• These are the techniques ASP.NET provides to store the user's specific
information or the state of the application on the server machine. It
completely makes use of server resources (the server's memory) to
store information.
• This management technique basically makes use of the following,
• Session State -user specific state that is stored on the server.
• Application State -The information is global of the application and is
available to all users regardless of the identity of the user requesting
the page.
Session State
• ASP.NET allows you to save values by using session state — which is
an instance of the HttpSessionState class
• Session is used to store user's information and/or uniquely identify a
user (or say browser). The Session basically stores the values as a
dictionary collection in key/value pairs. It completely utilizes server
resources to store the data. It is a secure way of storing data, since
the data will never be passed to the client.
• Session state is generally used for storing application data such as
inventory, supplier list, customer record, or shopping cart. It can also
keep information about the user and his preferences, and keep the
track of pending operations.
Session State ID
• The server maintains the state of user information by using a session
ID.
• When users makes a request without a session ID, ASP.NET creates a
session ID and sends it with every request and response to the same
user.
• For each and every user, a separate Session is created, and each and
every Session has its Unique ID. This ID is being stored in the client's
machine using cookies. If there are multiple users who are accessing a
web application, then for each user a separate Session is created.
Session Tracking
• ASP.NET tracks each session using a unique 120-bit identifier. ASP.NET
uses a proprietary algorithm to generate this value, thereby
guaranteeing that the number is unique and it’s random enough that
a malicious user can’t reverse -engineer or “guess” what session ID a
given client will be using.
• This ID is the only piece of session-related information that is
transmitted between the web server and the client.
Using Session State
• For this system to work, the client must present the appropriate
session ID with each request. You can accomplish this in two ways:
• Using cookies: In this case, the session ID is transmitted in a special
cookie (named ASP.NET_SessionId), which ASP.NET creates
automatically when the session collection is used. This is the default.
• Using modified URLs: In this case, the session ID is transmitted in a
specially modified (munged)URL. This allows you to create
applications that use session state with clients that don’t support
cookies.
Using Session State
• You can interact with session state using the
System.Web.SessionState.HttpSessionState class, which is provided in
an ASP.NET web page as the built-in Session object.
Important methods of Session object
• Abandon: It is used to end a user session.
• Clear: It clears all items from Session state.
• Remove: This method is used to remove a particular item from
Session state.
Storing and Retrieving Data in Session Object
Session State
Session state is global to your entire application for the current user.
However, session state can be lost in several ways:
• If the user closes and restarts the browser.
• If the user accesses the same page through a different browser
window, although the session will still exist if a web page is accessed
through the original browser window. Browsers differ on how they
handle this situation.
• If the session times out due to inactivity.
Four session storage mechanisms
• There are four session storage mechanisms provided by ASP.NET:
• In Proc mode
• State Server mode
• SQL Server mode
• Custom mode
• Off Mode
In Process mode
• In proc mode is the default mode provided by ASP.NET.
• InProc means Session state is stored in memory in the same process
as the ASP.NET process. So accessing data is very fast. Another
advantage is that there are no requirements of serialization to store
data in InProc Session Mode.
• If you restart your server, the state information will be lost.
State Server mode
• With this setting, ASP.NET will use a separate Windows service for
state management.
• This service runs on the same web server, but it’s outside the main
ASP.NET process, which gives it a basic level of protection if the
ASP.NET process needs to be restarted.
• The cost is the increased time delay imposed when state information
is transferred between two processes. If you frequently access and
change state information, this can make for a fairly unwelcome
slowdown.
SQL Server mode
• This setting instructs ASP.NET to use an SQL Server database to store
session information, as identified by the sqlConnectionString
attribute.
• This is the most resilient state store but also the slowest by far. To use
this method of state management, you’ll need to have a server with
SQL Server installed.
Custom Session mode
• Generally we should prefer in proc state server mode or SQL Server
mode but if you need to store session data using other than these
techniques then ASP.NET provides a custom session mode.
• This way we have to maintain everything customized even generating
session ID, data store, and also security.
Off
• This setting disables session state management for every page in the
application.
• This can provide a slight performance improvement for websites that
are not using session state.
Session Events in ASP.NET
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td colspan="3" align="center">
<asp:Label ID="lblmsg"
Text="President Election Form : Choose
your president"
runat="server" />
</td>
</tr>
<tr>
<td>
Candidate:
</td>
<td>
<asp:DropDownList ID="ddlcandidate"
runat="server" style="width:239px">
<asp:ListItem>Please choose a
candidate</asp:ListItem>
<asp:ListItem>Ajith </asp:ListItem>
<asp:ListItem>Varun</asp:ListItem>
<asp:ListItem>Sanju</asp:ListItem>
<asp:ListItem>Anila</asp:ListItem>
<asp:ListItem>Shilpa</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server" InitialValue="Please
choose a candidate" ControlToValidate ="ddlcandidate"
ErrorMessage="Please choose a candidate">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
House:
</td>
<td>
<asp:RadioButtonList ID="rblhouse"
runat="server">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="rblhouse"
ErrorMessage="Enter your house
name"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Class:
</td>
<td>
<asp:TextBox ID="txtclass"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="RangeValidator1"
runat="server" ControlToValidate="txtclass"
ErrorMessage="Enter your class (6 - 12)"
MaximumValue="12" MinimumValue="6"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtemail" runat="server"
style="width:250px"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemail"
ErrorMessage="Enter your email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.
\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:Button ID="Button1" runat="server"
style="text-align: center"
Text="Submit" onclick="Button1_Click"/>
</td>
</tr>
</table>
<asp:ValidationSummary
ID="ValidationSummary1" runat="server"
DisplayMode ="BulletList" ShowSummary ="true"
HeaderText="Errors:"/>
<asp:Label ID="lblmsg1" runat="server"
Text=""></asp:Label>
</div>
</form>
</body>
</html>
Module III
An Introduction To Database Programming
Syllabus – Module III
• An introduction to database programming – Introduction to relational
database, how to use SQL to work with data in database.
• Introduction to ADO.NET 4.
• How to use SQL data source, how to use custom statements and
stored procedures
• Data list controls, Data binding, advanced features of a SQL data
source.
ADO .NET
Introduction
• ADO stands for Microsoft ActiveX Data Objects.
• The ADO.NET is one of the Microsoft’s data access technology which
is used to communicate between the .NET Application (Console, WCF,
WPF, Windows, MVC, Web Form, etc.) and data sources such as SQL
Server, Oracle, MySQL, and XML documents.
Data Adapter
• DataAdapter Object populates a Dataset Object with results from a
Data Source . It is a special class whose purpose is to bridge the gap
between the disconnected Dataset objects and the physical data
source.
DataReader
• The DataReader Object is a stream-based , forward-only, read-only
retrieval of query results from the Data Source, which do not update
the data. DataReader requires a live connection with the database
and provides a very intelligent way of consuming all or part of the
result set.
Dataset
• DataSet provides a disconnected representation of result sets from
the Data Source, and it is completely independent from the Data
Source. DataSet provides much greater flexibility when dealing with
related Result Sets.
• DataSet contains rows, columns,primary keys, constraints, and
relations with other DataTable objects. It consists of a collection of
DataTable objects that you can relate to each other with DataRelation
objects. The DataAdapter Object provides a bridge between the
DataSet and the Data Source.
Dataset
DataSet
• The DataSet is the central component in the ADO.NET Disconnected
Data Access Architecture.
• A DataSet is an in-memory data store that can hold multiple tables at
the same time.
• DataSets only hold data and do not interact with a Data Source. One
of the key characteristics of the DataSet is that it has no knowledge of
the underlying Data Source that might have been used to populate it.
Thank You
Data Source Controls, Data
Controls and Data Binding
Data Source Controls
A data source control interacts with the data-bound controls and hides the
complex data binding processes.
These are the tools that provide data to the data bound controls and
support execution of operations like insertions, deletions, sorting, and
updates.
Each data source control wraps a particular data provider-relational
databases, XML documents, or custom classes and helps in:
• Managing connection
• Selecting data
• Managing presentation aspects like paging, caching, etc.
• Manipulating data
• Data source controls are server controls that you can drag onto your
page at design time. A data source control does not have a direct
visual component (you use data-bound controls for actual data
display).
• They allow you to declaratively define access to data found in objects,
XML, and databases.
Data Source Controls - Categories
• There are many data source controls available in ASP.NET for
accessing data from SQL Server, from ODBC or OLE DB servers, from
XML files, and from business objects.
• Based on type of data, these controls could be divided into two
categories:
• Hierarchical data source controls
• Table-based data source controls
Hierarchical
• The data source controls used for hierarchical data are:
• XMLDataSource - It allows binding to XML files and strings with or
without schema information.
• SiteMapDataSource - It allows binding to a provider that supplies site
map information.
So,
• The different data sources used in ASP.NET are
1. LinqDataSource: The Language Integrated Query in an ASP.NET web page is possible
using the markup. The insert, update, select, delete commands are supported. Filtering,
sorting and paging of the data are possible.
2. ObjectDataSource: User can work with the objects using the object data source.
3. SqlDataSource: User can work with Microsoft SQL Server, Oracle, OLEDB and Oracle
databases. The sorting, filtering, paging of the data is possible using the data source.
4. AccessDataSource: Working with Microsoft Access Database is possible using the data
source.
5. XmlDataSource: User can work with the XML file when the hierarchical structure needs
to be used as data source.
6. SiteMapDataSource: Site navigation data.
Data Source Views
• Every ASP.NET web form control inherits the DataBind method from
its parent Control class, which gives it an inherent capability to bind
data to at least one of its properties. This is known as simple data
binding or inline data binding.
• Simple data binding involves attaching any collection (item collection)
which implements the IEnumerable interface, or the DataSet and
DataTable classes to the DataSource property of the control.
Declarative data binding.
• Some controls can bind records, lists, or columns of data into their
structure through a DataSource control. These controls derive from
the BaseDataBoundControl class. This is called declarative data
binding.
• The data source controls help the data-bound controls implement
functionalities such as, sorting, paging, and editing data collections.
Simple Data Binding
• The FormView control renders a single record at a time from a data source
and provides the capability to page through multiple records, as well as to
insert, update, and delete records, similar to the DetailsView control.
• However, the difference between the FormView and
the DetailsView controls is that the DetailsView control uses a table-based
layout where each field of the data record is displayed as a row in the
control.
• In contrast, the FormView control does not specify a pre-defined layout for
displaying a record. Instead, you create templates that contain controls to
display individual fields from the record. The template contains the
formatting, controls, and binding expressions used to lay out the form.
DataList Control
• The DataList control renders data as table and enables you to display
data records in different layouts, such as ordering them in columns or
rows.
• You can configure the DataList control to enable users to edit or
delete a record in the table. (The DataList control does not take
advantage of the capabilities of data source controls for modifying
data; you must supply this code yourself.)
• The DataList control differs from the Repeater control in that
the DataList control explicitly places items in an HTML table, where as
the Repeater control does not.
ListView Control
• The ListView control displays data from a data source in a format that
you define using templates.
• The template contains the formatting, controls, and binding
expressions that are used to lay out the data.
• The ListView control is useful for data in any repeating structure,
similar to the DataList and Repeater controls.
• However, unlike the DataList and Repeater controls,
the ListView control implicitly supports edit, insert, and delete
operations, as well as sorting and paging functionality.
Templates
• Most Web server controls have a default look and layout, which you can
manipulate by setting properties or by using styles. Some Web server
controls also allow you to customize their look by using templates.
• A template is a set of HTML elements and controls that make up the layout
for a particular portion of a control.
• For example, in the DataList Web server control you can use a combination
of HTML elements and controls to create the layout for each row of the list.
• Similarly, the GridView Web server control has a default look for rows in the
grid. However, you can customize the grid's look by defining different
templates for individual columns.
Templates
• Templates consist of HTML and embedded server controls. When the
control runs in the ASP.NET Web page, the control infrastructure
renders the contents of the template in place of the default HTML for
the control.
Templates
• Itemtemplate: An Itemtemplate represents items in a Data Source; an
Itemtemplate renders in the web page as a number of records from
the Datasource Collection
Alternatiningtemplate: Applies a background-color or border-styles
to alternative rows in the Data Source collection
Headertemplate: HeaderTemplate is used to provide Headertext for
the data source collection
Footertemplate: Display footer text to the Data Source.
Data Controls
DataList Controls
• The ASP.NET DataList control is a light weight server side control that
works as a container for data items. It is used to display data into a list
format to the web pages.
• It displays data from the data source.
DataList Control
• DataList is a Databound control to display and manipulate data in a
web application.
• It is a composite control that can combine other ASP.Net controls and
it is present in the form.
• The DataList appearance is controlled by its template fields.
• The DataList control adds a table around the data items by default.
Template fields
• The following template fields are supported by the DataList control: