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

Module 5

This document discusses web application development and data access using ADO.NET. It describes the multi-tier architecture of web applications, which divides functionality into separate tiers, commonly including an information tier to store data, a business logic tier to implement application logic, and a client tier for the user interface. It also discusses validation controls in ASP.NET that validate user input, including required field, range, compare, regular expression, and custom validators, as well as the validation summary control.

Uploaded by

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

Module 5

This document discusses web application development and data access using ADO.NET. It describes the multi-tier architecture of web applications, which divides functionality into separate tiers, commonly including an information tier to store data, a business logic tier to implement application logic, and a client tier for the user interface. It also discusses validation controls in ASP.NET that validate user input, including required field, range, compare, regular expression, and custom validators, as well as the validation summary control.

Uploaded by

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

Programming Using C# & .

NET Module 5

Web App Development and DataAccess using ADO.NET

1.1. Multi-tier Applications Architecture:


Web-based applications are multitier applications and also referred as n-tier applications.
➢ Multitier applications divide functionality into separate tiers (that is, logical groupings of functionality).
➢ Tiers can be located on the same computer, the tiers of web-based applications commonly reside on
separate computers for security and scalability.

There are 3 tiers. They are:

i. Information Tier:
➢ The information tier also called the bottom tier.
➢ It maintains the application’s data.
➢ This tier typically stores data in a relational
database management system.
Example: A retail store might have a database for
storing product information, such as descriptions,
prices and quantities in stock.
The same database also might contain customer
information, such as user names, billing addresses
and credit card numbers.
➢ This tier can contain multiple databases, which
together comprise the data needed for an
application.

ii. Business Logic: Figure5.1: Basic architecture of a three-tier web-based


application
➢ The middle tier implements business logic,
controller logic and presentation logic to control interactions between the application’s clients and its
data.
➢ The middle tier acts as an intermediary between data in the information tier and the application’s clients.
➢ The middle-tier controller logic processes client requests (such as requests to view a product catalog)
and retrieves data from the database.
➢ The middle-tier presentation logic then processes data from the information tier and presents the content
to the client.
➢ Web applications typically present data to clients as web pages.
➢ Business logic in the middle tier enforces business rules and ensures that data is reliable before the server
application updates the database or presents the data to users.
➢ Business rules dictate how clients can and cannot access application data, and how applications process
data.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 1 | 11


Programming Using C# & .NET Module 5

Example: A business rule in the middle tier of a retail store’s web-based application might ensure that all
product quantities remain positive.
A client request to set a negative quantity in the bottom tier’s product information database would be rejected
by the middle tier’s business logic.

iii. Client Tier:


➢ The client tier, or top tier, is the application’s user interface, which gathers input and displays output.
➢ Users interact directly with the application through the user interface (typically viewed in a web
browser), keyboard and mouse.
➢ In response to user actions (Example: clicking a hyperlink), the client tier interacts with the middle
tier to make requests and to retrieve data from the information tier.
➢ The client tier then displays to the user the data retrieved from the middle tier.
➢ The client tier never directly interacts with the information tier.

1.2. Validation Controls in ASP.NET:


Validation control or Validator, which determines whether the data in another web control is in the proper
format.
• Validators provide a mechanism for validating user input on the client.
• When the page is sent to the client, the validator is converted into JavaScript that performs the validation
in the client web browser.
• JavaScript is a scripting language that executed on the client. Unfortunately, some client browsers might
not support scripting or the user might disable it.
For this reason, you should always perform validation on the server. ASP.NET validation controls can function
on the client, on the server or both.
An important aspect of creating ASP.NET Web pages for user input is to be able to check that the information
users enter is valid. ASP.NET provides a set of validation controls that provide an easy-to-use but powerful way
to check for errors and, if necessary, display messages to the user.
There are six types of validation controls in ASP.NET that listed below:
The below table describes the controls and their work:
Validation Control Description
RequiredFieldValidation Makes an input control a required field
Compares the value of one input control to the value of another input
CompareValidator
control or to a fixed value
RangeValidator Checks that the user enters a value that falls between two values
RegularExpressionValidator Ensures that the value of an input control matches a specified pattern
Allows you to write a method to handle the validation of the value
CustomValidator
entered
ValidationSummary Displays a report of all validation errors occurred in a Web page
All these validation control classes are inherited from the BaseValidator class hence they inherit its properties
and methods that are ControlToValidate, Display, EnableClientScript, Enabled, Text, isValid, and validate()
method.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 2 | 11


Programming Using C# & .NET Module 5

RequiredFieldValidator Control:
The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box
to force input into the text box.
Syntax: <asp:RequiredFieldValidator ID="rfvcandidate"
runat="server" ControlToValidate ="ddlcandidate"
ErrorMessage="Please choose a candidate"
InitialValue="Please choose a candidate">
</asp:RequiredFieldValidator>

RangeValidator Control:
The RangeValidator control verifies that the input value falls within a predetermined range.
It has three specific properties:
Properties Description
It defines the type of the data. The available values are: Currency, Date,
Type
Double, Integer, and String.
MinimumValue It specifies the minimum value of the range.
MaximumValue It specifies the maximum value of the range.

Syntax: <asp:RangeValidator ID="rvclass" runat="server"


ControlToValidate="txtclass"
ErrorMessage="Enter your class (6 - 12)" MaximumValue="12"
MinimumValue="6" Type="Integer">
</asp:RangeValidator>

CompareValidator Control:
The CompareValidator control compares a value in one control with a fixed value or a value in another control.
It has the following specific properties:
Properties Description
Type It specifies the data type.
ControlToCompare It specifies the value of the input control to compare with.
ValueToCompare It specifies the constant value to compare with.
It specifies the comparison operator, the available values are: Equal,
Operator NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual,
and DataTypeCheck.

Syntax:
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator">
</asp:CompareValidator>

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 3 | 11


Programming Using C# & .NET Module 5

RegularExpressionValidator:
The RegularExpressionValidator allows validating the input text by matching against a pattern of a regular
expression. The regular expression is set in the ValidationExpression property.
The following table summarizes the commonly used syntax constructs for
Regular expressions: \b, \n, \,\f, \r, \v, \t
Metacharacters: ., [abcd], [^abcd], [a-zA-Z], \w, \W, \s, \S, \d, \D
Quantifiers: *, +, ?, {n}, {n, }, {n,m}
Syntax:
<asp:RegularExpressionValidator ID="string" runat="server"
ErrorMessage="string" ValidationExpression="string"
ValidationGroup="string">
</asp:RegularExpressionValidator>

CustomValidator:
The CustomValidator control allows writing application specific custom validation routines for both the client
side and the server side validation.
➢ The client side validation is accomplished through the ClientValidationFunction property. The client
side validation routine should be written in a scripting language, such as JavaScript or VBScript, which
the browser can understand.
➢ The server side validation routine must be called from the control's ServerValidate eventhandler. The
server side validation routine should be written in any .Net language, like C# or VB.Net.
Syntax:
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction=.cvf_func.
ErrorMessage="CustomValidator">
</asp:CustomValidator>

ValidationSummary:
The ValidationSummary control does not perform any validation but shows a summary of all errors in the page.
The summary displays the values of the ErrorMessage property of all validation controls that failed validation.
The following two mutually inclusive properties list out the error message:
❖ ShowSummary : shows the error messages in specified format.
❖ ShowMessageBox : shows the error messages in a separate window.
Syntax:
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode = "BulletList" ShowSummary = "true"
HeaderText="Errors:" />

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 4 | 11


Programming Using C# & .NET Module 5

Validation Groups:
Complex pages have different groups of information provided in different panels. In such situation, a need might
arise for performing validation separately for separate group. This kind of situation is handled using validation
groups.
To create a validation group, you should put the input controls and the validation controls into the same logical
group by setting their ValidationGroup property.

1.3. Session Management in ASP.Net using Controls:


Cookies: Cookies provide you with a tool for personalizing web pages. A cookie is a piece of data stored by
web browsers in a small text file on the user’s computer. A cookie maintains information about the client during
and between browser sessions.

Session tracking using the .NET class HttpSessionState:


If the user clicks the link for book recommendations, the information stored in the user’s unique
HttpSessionState object is read and used to form the list of recommendations. That can be done using Session
property.

Session Property:
Every Web Form includes a user-specific HttpSessionState object, which is accessible through property Session
of class Page. We use this property to manipulate the current user’s HttpSessionState object.
When a page is first requested, a unique HttpSessionState object is created by ASP.NET and assigned to the
Page’s Session property.
The session object is created from the HttpSessionState class, which defines a collection of session state items.

The HttpSessionState class has the following properties:

Properties Description
SessionID The unique session identifier.
The value of the session state item with the specified name. This is the default
Item(name)
property of the HttpSessionState class.
Count The number of items in the session state collection.
Gets and sets the amount of time, in minutes, allowed between requests before
TimeOut
the session-state provider terminates the session.

The HttpSessionState class has the following methods:


Methods Description
Add(name, value) Adds an item to the session state collection.
Clear Removes all the items from session state collection.
Remove(name) Removes the specified item from the session state collection.
RemoveAll Removes all keys and values from the session-state collection.
RemoveAt Deletes an item at a specified index from the session-state collection.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 5 | 11


Programming Using C# & .NET Module 5

Example: The session state object is a name- void StoreSessionInfo(){


value pair to store and retrieve some String fromuser = TextBox1.Text;
Session["fromuser"] = fromuser;
information from the session state object. You }
could use the following code for the same: void RetrieveSessionInfo(){
String fromuser = Session["fromuser"];
Label1.Text = fromuser;
}

1.4. AJAX and other Technologies:


AJAX is differ from other technologies, such as ASP.NET and JSP, which use the postback model. To
understanding, you first need to analyse how other technologies work. Let’s understanding the working of
Traditional web applications with the below figure:
Traditional Web Applications are based on the request-response or
postback model.
❖ Each client interaction with the UI of a traditional Web
application, an Http request is sent to the server, which
processes the request and sends the results back to the
browser.
❖ At the time, when this request-response process is in progress,
seeing a blank screen can be quite frustrating at times.
❖ Considering modern scenario, when more and more transactions
are taking place through the Internet from all over the world, this
time-consuming process can be frustrating.
To remove this shortcoming, AJAX, which implements an entirely
different approach to web development, has been introduce as shows
the AJAX Web
Application model:
Traditional web application model

The AJAX Web Application model handles the client-side


activities, such as validations, without making a round trip to the
server.
The tasks that are required to be processed at the server-end are
handled by the AJAX engine.
The AJAX engine makes asynchronous calls to the server without
interrupting the user’s interactions with the UI; therefore it enhances
the user-interactivity and performance, which makes AJAX
different from other technologies.
AJAX web application model
Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 6 | 11
Programming Using C# & .NET Module 5

1.5. AJAX Control ToolKit:


The control toolbox in the Visual Studio IDE contains a group of controls
called the “AJAX Extensions”.

The ScriptManager Control:


The ScriptManager control is the most important control and must be
present on the page for other controls to work.
Syntax: <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

If you create an 'Ajax Enabled site' or add an 'AJAX Web Form' from the 'Add Item' dialog box, the web form
automatically contains the script manager control.
The ScriptManager control takes care of the client-side script for all the server side controls.

The UpdatePanel Control:


The UpdatePanel control is a container control and derives from the Control class. It acts as a container for the
child controls within it and does not have its own interface.
When a control inside it triggers a post back, the UpdatePanel interferes to initiate the post asynchronously and
update just that portion of the page.
Example: <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnpartial" runat="server"
onclick="btnpartial_Click" Text="Partial PostBack"/>
<br />
<br />
<asp:Label ID="lblpartial" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

Properties of the UpdatePanel Control

The following table shows the properties of the update panel control:
Properties Description
This property indicates whether the post backs are coming from the child
ChildrenAsTriggers
controls, which cause the update panel to refresh.
It is the content template and defines what appears in the update panel
ContentTemplate
when it is rendered.
RenderMode Shows the render modes. The available modes are Block and Inline.
UpdateMode Gets or sets the rendering mode by determining some conditions.
Defines the collection trigger objects each corresponding to an event
Triggers
causing the panel to refresh automatically.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 7 | 11


Programming Using C# & .NET Module 5

Methods of the UpdatePanel Control


The following table shows the methods of the update panel control:

Methods Description
Creates a Control object that acts as a container for child
CreateContentTemplateContainer
controls that define the UpdatePanel control's content.
Returns the collection of all controls that are contained in the
CreateControlCollection
UpdatePanel control.
Initializes the UpdatePanel control trigger collection if partial-
Initialize
page rendering is enabled.
Update Causes an update of the content of an UpdatePanel control.

The behavior of the update panel depends upon the values of the UpdateMode property and ChildrenAsTriggers
property.
UpdateMode ChildrenAsTriggers Effect
Always False Illegal parameters.
UpdatePanel refreshes if whole page refreshes or a
Always True
child control on it posts back.
UpdatePanel refreshes if whole page refreshes or a
Conditional False
triggering control outside it initiates a refresh.
UpdatePanel refreshes if whole page refreshes or a
Conditional True child control on it posts back or a triggering control
outside it initiates a refresh.

The UpdateProgress Control:


The UpdateProgress control provides a sort of feedback on the browser while one or more update panel controls
are being updated.
Example: While a user logs in or waits for server response while performing some database oriented job.
It provides a visual acknowledgement like "Loading page...", indicating the work is in progress.
Syntax: <asp:UpdateProgress ID="UpdateProgress1" runat="server"
DynamicLayout="true" AssociatedUpdatePanelID="UpdatePanel1" >

<ProgressTemplate>
Loading...
</ProgressTemplate>

</asp:UpdateProgress>

The above snippet shows a simple message within the ProgressTemplate tag.
However, it could be an image or other relevant controls. The UpdateProgress control displays for every
asynchronous postback unless it is assigned to a single update panel using the AssociatedUpdatePanelID
property.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 8 | 11


Programming Using C# & .NET Module 5

Properties of the UpdateProgress Control


The following table shows the properties of the update progress control:
Properties Description
Gets and sets the ID of the update panel with which this control is
AssociatedUpdatePanelID
associated.
Gets or sets the cascading style sheet (CSS) attributes of the
Attributes
UpdateProgress control.
Gets and sets the time in milliseconds after which the progress template is
DisplayAfter
displayed. The default is 500.
DynamicLayout Indicates whether the progress template is dynamically rendered.
Indicates the template displayed during an asynchronous post back which
ProgressTemplate
takes more time than the DisplayAfter time.

Methods of the UpdateProgress Control


The following table shows the methods of the update progress control:
Methods Description
Returns a list of components, behaviors, and client controls that are
GetScriptDescriptors
required for the UpdateProgress control's client functionality.
Returns a list of client script library dependencies for the UpdateProgress
GetScriptReferences
control.

The Timer Control


The timer control is used to initiate the post back automatically. This could be done in two ways:
i. Setting the Triggers property of the UpdatePanel control:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnpanel2" EventName="Click" />
</Triggers>

ii. Placing a timercontrol directly inside the UpdatePanel to act as a child control trigger. A single timer
can be the trigger for multiple UpdatePanels.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"> </asp:Timer>
<asp:Label ID="Label1" runat="server" Height="101px" style="width:304px">
</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 9 | 11


Programming Using C# & .NET Module 5

1.6. Controls are provide by AJAX on Server Side:


There are two Controls are provided by AJAX on Server Side: They are
i. TimerControl
ii. UpdateProgressControl

1.7. Standard web controls:


The basic controls available in ASP.NET. They are:

Web Controls Descriptions


Button When a user clicks a button, two events are raised: Click and Command
Syntax:
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Click" / >
Properties: Text, ImageUrl, Alternate Text, CausesValidation, PostBackUrl,
CommandName, CommandArgument
TextBox ✓ used to accept input from the user.
✓ can accept one or more lines of text depending upon the settings of the TextMode
attribute.
Syntax: <asp:TextBox ID="txtstate" runat="server"></asp:TextBox>
Label ✓ 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.
Syntax:
<asp:Label ID="txtstate" runat="server"></asp:Label>
Common Properties of the Text Box and Labels: TextMode, Text, MaxLength, Wrap, ReadOnly,
Columns, rows
DropDownList Displays a drop-down list of choices from which a user can select an item.
Syntax:
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
Properties: Items, Rows, SelectIndex, SelectedValue. SelectiionMode,
RadioButtonList Groups radio buttons.
Syntax:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>
Properties: RepeatLayout, RepeatDirection, Repeatolumns
HyperLink The HyperLink control is like the HTML <a> element.
Syntax:
<asp:HyperLink ID="HyperLink1" runat="server">
HyperLink
</asp:HyperLink>
Properties: ImageUrl, NavigateUrl, Text, Target.
Image The image control is used for displaying images on the web page, or some alternative
text, if the image is not available.
Syntax: <asp:Image ID="Image1" runat="server">
Properties: AlternateText, ImageAlign, ImageUrl
Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 10 | 11
Programming Using C# & .NET Module 5

1. Describe the Multi-tier application architecture, with a neat diagram


2. Mention the Standard web controls.
3. Explain different validation controls in ASP.NET.
4. What are cookies? Explain the session management in ASP.Net using controls.
5. List the various technologies that are used by AJAX.
6. Describe any 4 controls from AJAX control toolkit
7. How many controls are provided by AJAX on server side? Mention them.

Suma M G, AP, Dept. of MCA, RNSIT for updates: https://sites.google.com/view/sumamg-dotnet/ 11 | 11

You might also like