AWP Unit 2
AWP Unit 2
com
Acuity Educare
ADVANCED WEB
PROGRAMMING
SEM : V
SEM V: UNIT 2
Q. List and explain different files and folder in ASP.NET web application.
ASP.NET File Types: - ASP.NET applications can include many types of files. Below table
show list of files.
.aspx These are ASP.NET web pages. They contain the user
interface and, optionally, the underlying application code.
Users request or navigate directly to one of these pages to
start our web application
.ascx These are ASP.NET user controls. User controls are similar to
web pages, except that the user can’t access these files
directly. Instead, they must be hosted inside an ASP.NET
web page. User control allow you to develop a small piece of
user interface and reuse it in as many web forms as you want
without repetitive code.
global.asax This is the global application file. You can use this file to
define global variables (variables that can be accessed from
any web page in the web application) and react to global
events (such as when a web application first starts).
.cs These are code-behind files that contain C# code. They allow
you to separate the application logic from the user interface
of a web page.
Page 1 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Presentation Layer
The presentation layer consists of the Asp.net page that manages the appearance
of application. This layer can include bound data controls and ObjectDataSource
objects that bind data controls to the data.
Middle Layer
The middle layer contains the data access classes that manage the data access for
the application. This layer can also contain business objects that represent business
entities such as customers, products or employee and that implement business rules
such as credit and discount policies.
Database Layer
This layer consists of the database that contains the data for the application. Ideally
the SQL statement that do the database access should be saved in stored procedure
within the database, nut the SQL statement are often stored in the data access
classes.
Page 2 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Page load
At this stage, control properties are set using the view state and control state values.
Validation
Validate method of the validation control is called and if it runs successfully, the IsValid
property of the page is set to true.
Page rendering
At this stage, view state for the page and all controls are saved.
Unload
The rendered page is sent to the client and page properties, such as Response and
Request are unloaded and all cleanup done.
Page 3 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Page 4 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
The Global.asax file, also known as the ASP.NET application file, is an optional file
that contains code for responding to application-level events raised by ASP.NET or
by HttpModules.
The Global.asax file resides in the root directory of an ASP.NET-based application.
The Global.asax file is parsed and dynamically compiled by ASP.NET.
The Global.asax file itself is configured so that any direct URL request for it is
automatically rejected; external users cannot download or view the code written
within it.
The Global.asax file does not need recompilation if no changes have been made to
it. There can be only one Global.asax file per application and it should be located in
the application's root directory only.
The Global.asax contains two types of events those are
Events which are fired for every request
Events which are not fired for every request
Application_BeginRequest() – This event raised at the start of every request for the
web application. Application_EndRequest() – This event raised at the end of each
request right before the objects released.
Application_PreRequestHandlerExecute() – This event called before the appropriate HTTP
handler executes the request.
Application_PostRequestHandlerExecute() – This event called just after the request
is handled by its appropriate HTTP handler.
Events which are not fired for every request:-
Application_Start() – This event raised when the application starts up and
application domain is created.
Session_Start() – This event raised for each time a new session begins, This is a
good place to put code that is session-specific.
Application_Error() – This event raised whenever an unhandled exception occurs in
the application. This provides an opportunity to implement generic application-wide
error handling.
Session_End() – This event called when session of user ends.
Application_End() – This event raised just before when web application ends.
Application_Disposed() – This event fired after the web application is destroyed and
this event is used to reclaim the memory it occupies.
Web.Config
Configuration file is used to manage various settings that define a website. The
settings are stored in XML files that are separate from our application code. In
this way we can configure settings independently from our code.
Generally a website contains a single Web.config file stored inside the application root
directory. However there can be many configuration files that manage settings at
various levels within an application.
There are number of important settings that can be stored in the configuration file.
Some of the most frequently used configurations, stored conveniently inside
Web.config file are:
Database connections
Caching settings
Session States
Error Handling
Security
Benefits of XML-based Configuration files
ASP.NET Configuration system is extensible and application specific information can be
stored and retrieved easily. It is human readable.
We need not restart the web server when the settings are changed in configuration file.
ASP.NET automatically detects the changes and applies them to the running ASP.NET
application.
Configuration file looks like this
1. <configuration>
2. <connectionStrings>
3. <add name="myCon"connectionString=" server=MyServer; database=puran;
uid=abcd;pwd=abcd1234" />
4. </connectionStrings>
5. </configuration>
Page 6 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
This is an input control which is used to take user input. To create TextBox either
we can write code or use the drag and drop facility of visual studio IDE.
This is server side control, asp provides own tag to create it. The example is given below.
< asp:TextBoxID="TextBox1" runat="server" ></asp:TextBox>
This control has its own properties that are tabled below.
Property Description
Text It is used to set text to be shown for the control.
Page 7 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
These controls differ only in how they appear to the user. A button displays text
within a rectangular area. A Link button displays text that look like a hyperlink and
an image button displays an image.
LinkButton control is a control just like a Button control along with the
flexibility to make it look like a Hyperlink. It implements an anchor <a/> tag
that uses only ASP.NET postback mechanism to post the data on the server.
Despite being a hyperlink, we can't specify the target URL. ImageButton
control is used to post the form or fire an event either client side or server side.
It’s like a asp:Button control, the only difference is, we have the ability to place
our own image as a button. ImageButton control is generally used to post the
form or fire an event either client side or server side.
Button control is used to post the form or fire an event either client side or
server side. Button control is generally used to post the form or fire an event
either client side or server side. When it is rendered on the page, it is generally
implemented through <input type=submit> HTML tag.
CheckBox:
CheckBox control is an asp.net web server control. CheckBox control visually as
square on web forms. The Checkbox control allow user to check square or uncheck
square. In CheckBox control check and uncheck checkbox specify by the checked
property of check box true or false.
Basic syntax for check box:
<asp:CheckBox ID= "chkoption" runat= "Server"></asp:CheckBox>
CheckBox properties:
AutoPostBack:Specifies whether the form should be posted immediately after
the Checked property has changed or not. Default is false
Page 8 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
RadioButton
Radiobutton isasp.net web server control. Radiobutton is used to allow user to select a
single radiobutton from group of radiobutton. In asp.net generally we use more
than one radiobutton and select only one radiobutton at a time from all the
radiobutton control. On other hand in checkbox control we can check and uncheck
multiple check box at a time.
Basic syntax for radio button:
RadioButton properties:
AutoPostBack:A Boolean value that specifies whether the form should be posted
immediately after the Checked property has changed or not. Default is false
Checked : A Boolean value that specifies whether the radio button is checked or not
id a unique id for the control
GroupName : The name of the group to which this radio button belongs
Text : The text next to the radio button
Page 9 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Q. What is the difference between List Box and Drop-Down Lists? List and
explain any three common properties of these controls.
List boxes are used in cases where there are small numbers of items to be selected. In
contrast, drop-down lists are typically used with larger list so that they don’t take up
much space on the page.
A list box lets a user select one or more items from the list of items. A drop-
down list lets a user choose an item from the drop-down list of items.
Following are common properties of ListBox and DropDownList:
Page 10 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Properties Description
Items Gets the collection of items from the dropdown box.
SelectedValue Get the value of the Selected item from the dropdown box.
SelectedIndex Gets or Sets the index of the selected item in the dropdown box.
SelectedItem Gets the selected item from the list.
Sorted
The Sorted property set to true, the ListBox items are sorted. The following code
snippet sorts the ListBox items.
listBox1.Sorted = true;
Selected Mode:
SelectionMode property defines how items are selected in a ListBox. The
SelectionMode value can be one of the following four SelectionMode enumeration
values. None - No item can be selected. One - Only one item can be selected.
MultiSimple - Multiple items can be selected. MultiExtended - Multiple items can
be selected, and the user can use the SHIFT, CTRL, and arrow keys to make
selections.
listBox1.SelectionMode = SelectionMode.MultiSimple;
ListBox1.SetSelected(1, true);
listBox1.SetSelected(2, true);
Page 11 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
MultiColumn:
A multicolumn ListBox places items into as many columns as are needed to make vertical
scrolling unnecessary. The user can use the keyboard to navigate to columns that are not
currently visible. Set the HorizontalScrollbar property to true to display a horizontal scroll
bar that enables the user to scroll to columns that are not currently shown in the visible
region of the ListBox. The value of the ColumnWidth property determines the width of
each column.
listBox1.MultiColumn = true;
SelectedItem
Gets or sets the currently selected item in the ListBox. We can get text associated
with currently selected item by using Items property.
string selectedItem = listBox1.Items[listBox1.SelectedIndex].ToString();
SelectedIndex
Gets or sets the zero-based index of the currently selected
item in a ListBox.
listBox1.SelectedIndex = 1;
Table control is used to structure a web pages. In other words to divide a page into
several rows and columns to arrange the information or images. When it is rendered
on the page, it is implemented through <table> HTML tag. We can simply use
HTML <table> control instead of using <asp:Table> control. However many of one
benefits of using <asp:Table> control is we can dynamically add rows or columns at
the runtime or change the appearance of the table. Following are some important
properties that are very useful.
BackImageUrl Used to set background image of the table
Caption Used to write the caption of the table.
Example:
ASP.NET code for a table control
<asp:Table ID="Table1" runat="server" Height="123px" Width="567px">
<asp:TableRow runat="server">
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
</asp:TableRow>
</asp:Table>
Page 12 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Page 13 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
The AdRotator is one of the rich web server control of asp.net. AdRotator control is
used to display a sequence of advertisement images as per given priority of image.
Adrotator control display the sequence of images, which is specified in the external
XML file. In xml file we indicate the images to
display with some other attributes, like image impressions, NavigateUrl,
ImageUrl, AlternateText.
In Adrotator control images will be changed each time while refreshing the web page.
AdRotator Control Example in ASP.Net
advertisement file:
Page 14 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
<Ad>
<ImageUrl>rose2.jpg</ImageUrl>
<NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>
<AlternateText>Order roses and flowers</AlternateText>
<Impressions>20</Impressions>
<Keyword>gifts</Keyword>
</Ad>
<Ad>
<ImageUrl>rose3.jpg</ImageUrl>
<NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>
<AlternateText>Send flowers to Russia</AlternateText>
<Impressions>20</Impressions>
<Keyword>russia</Keyword>
</Ad>
</Advertisements>
Create a new web page and place an AdRotator control on it.
<form id="form1" runat="server">
<div>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile ="~/ads.xml"
onadcreated="AdRotator1_AdCreated" />
</div>
</form>
Object->Control->WebControl->Calendar
The Calendar is complex, powerful Web server control that you can use to add
calendar feature to our web page. We can use calendar control display any date
between 0 A.D. and 9999A.D.The Calendar control is represented as:
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
Page 15 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
The Calendar control when rendered to a user browser, it generates an HTML <table>
element and a set of associated JavaScript. The Calendar control can be used to select a
single date or multiple dates. The SelectionMode property is used for this. The
SelectionMode properties are as:
Page 16 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Page 17 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Q. What is user control? How to create and use user control in ASP.NET Page.
<%@RegisterTagPrefix="My"TagName="UserInfoBoxControl"Src="~/UserInfoBoxCont
rol.ascx" %>
Make sure that the src value matches the path to your UserControl file. Now you
may use the UserControl in your page, like any other control. For instance, like this:
<My:UserInfoBoxControlrunat="server"ID="MyUserInfoBoxControl"/>
Q. Why we use validation controls? List various types of controls used in asp.net
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:
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.
Page 18 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Page 19 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
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 syntax of the control is as given:
<asp:RegularExpressionValidator ID="string" runat="server" ErrorMessage="string"
ValidationExpression="string" ValidationGroup="string">
</asp:RegularExpressionValidator
Q. What is the use of Compare Validator? Explain it along with its properties.
CompareValidator Control
The CompareValidator control allows you to make comparison to compare data entered
in an input control with a constant value or a value in a different control.
It can most commonly be used when you need to confirm password entered by the
user at the registration time. The data is always case sensitive.
It has the following specific properties:
Example:
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 event
handler. The server-side validation routine should be written in any .Net language, like C#
or VB.Net.
Below table shows the properties of CustomValidator.
Example:
In this below example we will simply check the length of the string in the TextBox. Custom
Text:<br />
<asp:TextBox runat="server" id="txtCustom" />
<asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom"
onservervalidate="cusCustom_ServerValidate" errormessage="The text must be exactly 8
characters long!" />
<br /><br />
protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e){
if(e.Value.Length == 8)
e.IsValid = true; else
e.IsValid = false;
}
Page 21 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
The Menu control is used to create a menu of hierarchical data that can be used to
navigate through the pages. The Menu control conceptually contains two types of items.
First is StaticMenu that is always displayed on the page, second is DynamicMenu that
appears when opens the parent item. Following steps are used to create Menu Control:
Toolbox > Navigation > Menu or add the following few lines of code snippet.
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<Items>
<asp:MenuItem Text="HOME" NavigateUrl="~/Default.aspx" Selected="true" />
<asp:MenuItem Text="HTML" NavigateUrl="~/HTML.aspx">
<asp:MenuItem Text="HtmlTagList" NavigateUrl="~/HtmlTagList.aspx" />
</asp:MenuItem>
Page 22 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
Each node in the Tree is represented by a name/value pair (not necessarily unique),
defined by the Text and Value properties of TreeNode, respectively. The text of a
node is rendered, whereas the value of a node is not rendered and is typically used
as additional data for handling postback events.
This example also uses the ExpandDepth property of TreeView to automatically
expand the tree 1 level deep when it is first rendered.
The TreeView control is made up of one or more nodes. Each entry in the tree is called a
node and is represented by a TreeNode
Page 23 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT2
The SiteMapPath control basically is used to access web pages of the website from
one webpage to another. It is a navigation control and displays the map of the site
related to its web pages.
This map includes the pages in the particular website and displays the name of those
pages. We can click on that particular page in the Site Map to navigate to that page.
We can say that the SiteMapPath control displays links for connecting to URLs of other
pages.
The SiteMapPath control uses a property called SiteMapProvider for accessing data
from databases and it stores the information in a data source.
The representation of the SiteMapPath control is as follows:
Root Node->Child Node
PathSeperator : It specifies the string that displays the SiteMapPath nodes in the
rendered navigation path.
Style properties of the SiteMapPath class
CurrentNodeStyle : It specifies the style used for the display text for the current node.
RootNodeStyle : It specifies the style for the root node style text.
NodeStyle : It specifies the style used for the display text for all nodes in the site
navigation path.
Sitemap file has been included in our project and we can see it in the Solution
Explorer. And now we have to set the URL and title attributes in the sitemap file.
<?xml version="1.0" encoding="utf-8" ?>
Page 24 of 24
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622