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

Unit 3 - Introduction to ASP. Net

The document provides an introduction to ASP.NET 2.0, detailing its features, functionality, and the stages in web forms processing. It explains how ASP.NET is a server-side web application framework developed by Microsoft, highlighting improvements in productivity, security, and data access. Additionally, it outlines the life cycle of web forms and the types of server controls available for creating dynamic web pages.

Uploaded by

JINESH VARIA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit 3 - Introduction to ASP. Net

The document provides an introduction to ASP.NET 2.0, detailing its features, functionality, and the stages in web forms processing. It explains how ASP.NET is a server-side web application framework developed by Microsoft, highlighting improvements in productivity, security, and data access. Additionally, it outlines the life cycle of web forms and the types of server controls available for creating dynamic web pages.

Uploaded by

JINESH VARIA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to ASP.NET 2.

3.0 Objectives
3.1 Introduction
3.2 Features of ASP.net 2.0
3.3 Stages in Web Forms Processing
3.4 Introduction to Server Controls
3.5 HTML Controls
3.6 Validation Controls
3.7 User Control
3.8 Data Binding Controls
3.9 Configuration
3.10 Personalization
3.10.1 User profiles
3.10.2 Personalization Providers
3.10.3 Using personalization
3.10.4 Defining profiles in Web .Config
3.10.5 User Profile information
3.10.6 Saving Profile Changes
3.10.7 Profiles and Users
3.11 Session State
3.12 Summary
3.13 Check your Progress - Answers
3.14 Questions for Self – Study
3. 15 Suggested Readings

3.0 OBJECTIVES
After studying this Chapter You will be able to –
 explain the features of ASP.NET 2.0
 discuss how Web Forms pages work in Web applications
 discuss the HTML server controls with validation.
 state Data Binding control in .NET
 describe configuration and personalization?
3.1 INTRODUCTION
ASP.NET is a server-side Web application framework designed for Web
development to produce dynamic Web pages. It was developed by Microsoft to allow
programmers to build dynamic web sites, web applications and web services.
ASP.NET is the latest version of Microsoft's Active Server Pages technology
(ASP).
It is the next generation ASP, but it's not an upgraded version of ASP.
ASP.NET is an entirely new technology for server-side scripting. It was written from the
Introduction to ASP .NET 2.0 / 27
ground up and is not backward compatible with classic ASP. ASP.NET is the major
part of the Microsoft's .NET Framework.
Before you continue you should have a basic understanding of the following:
WWW, HTML, XML and the basics of building Web pages scripting languages like
JavaScript or VBScript the basics of server side scripting like ASP or PHP

What is ASP.NET?
ASP.NET is a server side scripting technology that enables scripts (embedded in web
pages) to be executed by an Internet server.
 Microsoft Technology
 ASP.NET is a program that runs inside IIS
 IIS (Internet Information Services) is Microsoft's Internet server
 IIS comes as a free component with Windows servers
 IIS is also a part of Windows 2000 and XP Professional

What is an ASP.NET File?


 An ASP.NET file is just the same as an HTML file
 An ASP.NET file can contain HTML, XML, and scripts
 Scripts in an ASP.NET file are executed on the server
 An ASP.NET file has the file extension ".aspx"

How Does ASP.NET Work?


 When a browser requests an HTML file, the server returns the file
 When a browser requests an ASP.NET file, IIS passes the request to the
ASP.NET engine on the server
 The ASP.NET engine reads the file, line by line, and executes the scripts in
the file
 Finally, the ASP.NET file is returned to the browser as plain HTML

3.2 FEATURES OF ASP.NET 2.0

ASP.NET 2.0 improves ASP.NET by adding several new features.

Design goals for ASP.NET 2.0:

 Increase productivity by removing 70% of the code


 Use the same controls for all types of devices
 Provide a faster and better web server platform
 Simplify compilation and installation
 Simplify the administration of web applications

Some of the new features in ASP.NET 2.0 are:

 Master Pages, Themes, and Web Parts


 Standard controls for navigation
 Standard controls for security
 Roles, personalization and internationalization services
 Improved and simplified data access controls

ASP .NET / 28
 Full support for XML standards like, XHTML, XML, and WSDL
 Improved compilation and deployment (installation)
 Improved site management
 New and improved development tools

The new features are described below.

1) Master Pages : ASP.NET didn't have a method for applying a consistent look
and feel for a whole web site. Master pages in ASP.NET 2.0 solve this problem.
A master page is a template for other pages, with shared layout and
functionality. The master page defines placeholders for content pages. The
result page is a combination (merge) of the master page and the content page.

Master Page Example:

<%@ Master %>


<html>
<body>
<h1>Standard Header For All Pages</h1>
<asp:ContentPlaceHolder id="CPH1" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>

2) Themes : Themes are another feature of ASP.NET 2.0. Themes, or skins, allow
developers to create a customized look for web applications.

Design goals for ASP.NET 2.0 themes:

 Make it simple to customize the appearance of a site


 Allow themes to be applied to controls, pages, and entire sites
 Allow all visual elements to be customized

3) Web Parts : ASP.NET 2.0 Web Parts can provide a consistent look for a site,
while still allowing user customization of style and content.
New controls:
 Zone controls - areas on a page where the content is consistent
 Web part controls - content areas for each zone

4) Navigation : ASP.NET 2.0 has built-in navigation controls like

 Site Maps
 Dynamic HTML menus
 Tree Views

5) Security : Security is very important for protecting confidential and personal


information. In ASP.NET 2.0 the following controls has been added:

 A Login control, which provides login functionality


 A LoginStatus control, to control the login status
 A LoginName control to display the current user name
 A LoginView control, to provide different views depending on login status
 A CreateUser wizard, to allow creation of user accounts
 A PasswordRecovery control, to provide the "I forgot my password"
functionality

6) Roles and Personalization: Internet communities are growing very popular.


ASP.NET 2.0 has personalization features for storing user details. This provides
an easy way to customize user (and user group) properties.

Introduction to ASP .NET 2.0 / 29


7) Internationalization: Reaching people with different languages is important if
you want to reach a larger audience. ASP.NET 2.0 has improved support for
multiple languages.

8) Data Access: Many web sites are data driven, using databases or XML files as
data sources. With ASP.NET this involved code, and often the same code had to
be used over and over in different web pages. A key goal of ASP.NET 2.0 was to
ease the use of data sources. ASP.NET 2.0 has new data controls, removing
much of the need for programming and in-depth knowledge of data connections.

9) Mobility Support: The problem with Mobile devices is screen size and display
capabilities. In ASP.NET, the Microsoft Mobile Internet Toolkit (MMIT) provided
this support. In ASP.NET 2.0, MMIT is no longer needed because mobile
support is built into all controls.

10) Images: ASP.NET 2.0 has new controls for handling images:

 The ImageMap control - image map support


 The DynamicImage control - image support for different browsers

These controls are important for better image display on mobile devices, like hand-
held computers and cell phones.

11) Automatic Compilation: ASP.NET 2.0 provides automatic compilation. All files
within a directory will be compiled on the first run, including support for WSDL,
and XSD files.

12) Compiled Deployment (Installation) and Source Protection: ASP.NET 2.0


also provides pre-compilation. An entire web site can be pre-compiled. This
provides an easy way to deploy (upload to a server) compiled applications, and
because only compiled files are deployed, the source code is protected.

13) Site Management: ASP.NET 2.0 has three new features for web site
configuration and management:
 New local management console
 New programmable management functions (API)
 New web-based management tool

14) Development Tools: With ASP.NET Visual Studio.NET was released with
project and design features targeted at corporate developers. With ASP.NET
2.0, Visual Studio 2005 was released. Key design features for Visual Studio
2005 include:
 Support for the features described above
 Upload files from anywhere (FTP, File System, Front Page....)
 No project files, allowing code to be manipulated outside Visual Studio
 Integrated Web Site Administration Tool
 No "build" step - ability to compile on first run

Visual Web Developer is a new free ASP.NET 2.0 tool for non-corporate developers
who don't have access to Visual Studio.NET.

ASP .NET / 30
Check your progress 3.2
Answer the following questions in 1-2 sentences.
a) What is ASP.NET?
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…
b) Write any two ASP.NET features.
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…

3.3 STAGES IN WEB FORMS PROCESSING


Web Forms Page Life Cycle: In general, the life cycle for a Web Forms page
is similar to that of any Web process that runs on the server. Certain characteristics of
Web processing information is passed via HTTP protocol, the stateless nature of Web
pages, and so on. However, the ASP.NET page framework performs many Web
application services for us. It is important to understand the sequence of events that
occur when a Web Forms page is processed.
The Life Cycle of a Web Forms Page: It will be helpful to understand some
fundamental characteristics of how Web Forms pages work in Web applications
before we examine the details of what goes on inside a page when it is processed.
Round Trips : Most Web pages require processing on the server. For
example, consider a products page used to check the availability of a certain product.
When a user selects his product and hits the submit button the page must check on
the server to see whether the selected product is available or not. This kind of
functionality is achieved by handling server control events. Whenever a user
interaction requires processing on the server, the Web page is posted back to the
server processed and is returned back to the browser. This sequence is called round
trip.
The image below demonstrates server round trip.

Introduction to ASP .NET 2.0 / 31


In any Web scenario, Web pages are recreated with every round trip. When
the server finishes processing and sends the page to the browser, it discards the page
information. This frees server resources after each request and a Web application can
scale to support hundreds or thousands of simultaneous users. The next time the page
is posted, the server starts over in creating and processing it, and for this reason, Web
pages are said to be stateless. Stateless means the values of a page's variables and
controls are not saved on the server.

Limitations of ASP.NET are as follows:

 ASP.NET saves page and control properties between round trips. This is
referred to as saving the view state of the control.
 It provides state management facilities so that you can save your own variable
and application-specific or session-specific information between round trips.
 It can detect when a form is requested for the first time versus when the form
is posted, and allows you to program accordingly. You may want a different
behavior during a page postback versus an initial request.

Stages in Web Forms Processing:

Stage Means Use


Page Initialization The page's Page_Init event During this event, the ASP.NET
is raised, and the page and page framework restores the
control view state are control properties and postback
restored. data.
User Code The page's Page_Load Read and restore values stored
Initialization event is raised. previously, Using the
Page.IsPostBack property, check
whether this is the first time the
page is being processed. If this
is the first time the page is being
processed then perform initial
data binding. Otherwise, restore
control values. Read and update
control properties.
Validation The Validate method of any Test the outcome of validation in
validator Web server an event handler
controls is invoked to
perform the control's
specified validation.
Event Handling If the page was called in Perform application-specific
response to a form event, processing and handle the
the corresponding event specific event raised.
handler in the page is called
during this stage
Cleanup The Page_Unload event is Perform final cleanup work.
called because the page has Close files, closing database
finished rendering and is Connections and discard
ready to be discarded. objects.

Check your progress 3.3


Answer the following questions in 1-2 sentences.
a) What is Web form page life cycle?
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…
b) State the stages of Web form processing.
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…

ASP .NET / 32
3.4 INTRODUCTION TO SERVER CONTROLS
For creating Web Forms pages, you can use these types of controls:
 HTML server controls HTML elements exposed to the server so you can
program them. HTML server controls expose an object model that maps very
closely to the HTML elements that they render.
 Web server controls with more built-in features than HTML server controls. Web
server controls include not only form-type controls such as buttons and text boxes,
but also special-purpose controls such as a calendar. Web server controls are
more abstract than HTML server controls in that their object model does not
necessarily reflect HTML syntax.
 Validation controls that incorporate logic to allow you to test a user's input. You
attach a validation control to an input control to test what the user enters for that
input control. Validation controls are provided to allow you to check for a required
field, to test against a specific value or pattern of characters, to verify that a value
lies within a range, and so on.
 User controls that you create as Web Forms pages. You can embed Web
Forms user controls in other Web Forms pages, which is an easy way to create
menus, toolbars, and other reusable elements.
Every server control has a tag with the runat="server" attribute and is
converted to client-specific XHTML. ASP.NET server controls are objects and have
their own properties, methods and event handlers. Interesting to know is that server
controls can keep their state (value and design) stored between subsequent page
requests thanks to StateView.
Every control is derived from the Control class and inherits the properties and the
methods of this Control class. The most useful inherited properties are:
 Controls: gives a collection with all the child controls for a specified server
control
 EnableViewState: Boolean to decide whether the control has to track his
current state or not
 ID: id of the server control, maybe the most important property
 Visible: Boolean to decide if the control will be rendered
The most useful inherited methods are:
 DataBind(): binds the control with a certain data source (e.g. resultset of an sql
query)
 FindControl(): searches a child control with the given name (string)
 HasControls(): Booleans that defines if this server control owns child controls
1) Page in ASP.NET
It might sound strange but the whole page is a control itself and acts as
container for everything that is placed in it. Some of the properties are: Title,
Session, Cache, Trace, Special on the Page control are the directives (start with
a @). In the Page directive you find what language is used for the code behind,
the path to the source file and the name of the class in the code behind and
possible extra properties for the page document.
2) Label Control
The Label control displays text in a set location on the page. Unlike static text,
the Text property of a label can be changed programmatically. Layout of the
text can be done programmatically by changing properties or with HTML tags
(which are allowed) in the text itself.
3) TextBox Control
The TextBox control enables the user to enter text. You have the possibility to
use the textbox as a single line, multiline or password field by changing the
TextMode property. The display width of a textbox is determined by its
Columns property and the height of a textbox is determined by the Rows
property (only for MultiLine textmode). You can limit the number of signs the
user can enter for a textbox with its textmode set to SingleLine or Password by
entering a value for MaxLength.

Introduction to ASP .NET 2.0 / 33


A very useful event for the TextBox control is OnTextChanged. When the
cursor focus leaves the textbox this event is triggered. You can use this event to
control the input at the very moment the user is done with editing his text.

<form id="form1" runat="server">


<div>
<br />
<br />
<asp:TextBox ID="txtSingleLine" runat="server" Columns="10"
MaxLength="40"></asp:TextBox>
<asp:TextBox ID="Password" runat="server" Columns="10"
TextMode="Password"></asp:TextBox>
<br />
<asp:TextBox ID="txtMultiLine" runat="server" Columns="10" Rows="5"
TextMode="Multiline">
</asp:TextBox>
</div>
</form>

4) Button Control
The Button control is used to submit the form back to the server (postback). This
happens automatically in opposite to other controls where you have to enable
the AutoPostBack property to have the same effect. Buttons have a Causes
Validation property to trigger validation of all validation controls assigned to the
same group.
It is possible to use several buttons in a container control like a DataGrid or a
GridView. All these buttons have the same ID and it will be impossible to bind an
event handler to each button control's OnClick event (or other event) to
determine the particular button that was clicked. That's why buttons have a
CommandName and CommandArgument property to determine which
button you clicked and deliver the correct arguments to the event handler.
There are three types of buttons: the standard button, the ImageButton
(image acting as a button) and the LinkButton (link acting as a button). Notice
that the ImageButton doesn't have a Text property, but instead it does have an
AlternateText property which shows the entered text if the browser doesn't
support images.

<asp:Button ID="btnButton" runat="Server" Text="Button" />


<asp:ImageButton ID="imgImageButton" runat="Server" ImageUrl="image.jpg" />
<asp:LinkButton ID="lnkLinkButton" runat="Server">Link Button</asp:LinkButton>
The most important event for a Button control is the OnClick event. This event is
triggered with a click on the button and submits the form to the server. The
OnCommand event is also triggered with a click on the button, but the values of
CommandName and CommandArgument are also passed to the event.

ASP .NET / 34
5) DropDownList Control
The DropDownList control provides a single-select dropdown list. Each list item
has a value and an index. You can add items to the list one by one yourself or
by data binding a static array or another data source (e.g. results from a sql
query). To bind a data source you'll be using the DataTextField property to
link the text content and the DataValueField property to link the value of each
list item.
There are several ways to add items to the list at Design time. In design view
you can use the smart tag 'Edit items' which shows on the dropdown list or you
can click on the "..." next to the property Items. Both give the same window in
which you can add the items one by one. Or you can write the code for each list
item in the source view.

<asp:DropDownList ID="ddlDropDownList" runat="Server">


<asp:ListItem Value="1">First Item</asp:ListItem>
<asp:ListItem Value="2">Second Item</asp:ListItem>
<asp:ListItem Selected="True" Value="1">Third Item</asp:ListItem>
</asp:DropDownList>
Adding items is not only limited to design time but can be done during run-time
too. The best place to do this is in the Page_Load so you're sure everything is in your
dropdown list before it is shown. It doesn't matter if you want to add them one by one
or by data binding, both work fine.
if (!Page.IsPostBack) {
// adding these one by one yourself
ddlBackColor.Items.Add(new ListItem("red", "1"));
ddlBackColor.Items.Add(new ListItem("green", "2"));
ddlBackColor.Items.Add(new ListItem("blue", "3"));
ddlBackColor.Items.Add(new ListItem("yellow", "4"));

// adding these to an ArrayList and databinding the ArrayList


// note this could have been replaced with results from a sql query
ArrayList fontList = new ArrayList();
fontList.Add("Arial");
fontList.Add("Courier");
ddlFont.DataSource = fontList;
ddlFont.DataBind();
}
You can use the OnSelectedIndexChanged event to dynamically change
layout/content of your web page when the user chooses another item in the list. But
don't forget to put the AutoPostBack property on true if you want this to happen
automatically without having to click on a button.

Introduction to ASP .NET 2.0 / 35


6) CheckBox(List) Control
The CheckBox control accepts Boolean input and stores it in the Checked
property: true if the box is selected or false if it's not selected. Typically a
checkbox is processed as one of several fields in a form. The CheckBoxList
control provides a multiple-selection checked list. Like other list controls,
CheckBoxList has an Items collection that corresponds to each item (CheckBox)
in the list. You can test the Selected property of each item. You can choose to
render the list in with or without table structure by the RepeatLayout property.
Next to that you can also choose to render the list horizontally or vertically by
changing the RepeatDirection property.
7) RadioButton(List) Control
The RadioButton control permits you to intersperse the radio buttons in a group
with other content on the page. Be sure you group the RadioButtons logically by
giving them all the same GroupName or you'll be able to select more than
one.
If you tend to forget grouping the radio buttons, it might be better to use
RadioButtonList. The RadioButtonList control provides a single-selection
checked list. You can change the rendering like you did with a CheckBoxList.

8) Panel Control
The panel control is mainly used as a container for other controls. It's useful to
group, hide or generate controls programmatically. If you generate controls
programmatically you'll have to recreate them every time you load the page
since the ViewState only remembers the state and not the controls you
generated. If you only want to generate controls you can replace the panel by a
PlaceHolder.
3.5 HTML CONTROLS
HTML elements in ASP.NET files are, by default, treated as text. To make
these elements programmable, add a runat ="server" attribute to the HTML element.
This attribute indicates that the element should be treated as a server control.

Note: ASP.NET requires that all HTML elements must be properly closed and properly
nested.

HTML Server Control Description


HtmlAnchor Controls an <a> HTML element
HtmlButton Controls a <button> HTML element
HtmlForm Controls a <form> HTML element
HtmlGeneric Controls other HTML element not specified by a specific
HTML server control, like <body>, <div>, <span>, etc.
HtmlImage Controls an <image> HTML element
HtmlInputButton Controls <input type="button">, <input type="submit">, and
<input type="reset"> HTML elements
HtmlInputCheckBox Controls an <input type="checkbox"> HTML element
HtmlInputFile Controls an <input type="file"> HTML element
HtmlInputHidden Controls an <input type="hidden"> HTML element
HtmlInputImage Controls an <input type="image"> HTML element
HtmlInputRadioButton Controls an <input type="radio"> HTML element
HtmlInputText Controls <input type="text"> and <input type="password">
HTML elements
HtmlSelect Controls a <select> HTML element
HtmlTable Controls a <table> HTML element
HtmlTableCell Controls <td>and <th> HTML elements
HtmlTableRow Controls a <tr> HTML element
HtmlTextArea Controls a <textarea> HTML element

ASP .NET / 36
1) Example of HTMLButton

<script runat="server">
Sub button1(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the blue button!"
Sub button2(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the pink button!"
End Sub
</script>

<html>
<body>

<form runat="server">
<button id="b1" OnServerClick="button1"
style="background-color:#e6e6fa;
height=25;width:100" runat="server">
Blue button!
</button>
<button id="b2"
OnServerClick="button2"
style="background-color:#fff0f5;
height=25;width:100" runat="server">
Pink button!
</button>
<p id="p1" runat="server" />
</form>

</body>
</html>

Output Result

2) Example of HTMLForm
<script language = “vb” runat= "server">
if name.value<>"" then
p1.InnerHtml="Welcome " & name.value & "!"
end if
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name: <input id="name" type="text" size="30" runat="server" />
<br /><br />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>

Introduction to ASP .NET 2.0 / 37


Output Result

3) Example of HtmlInputCheckBox
<script language = “vb” runat="server">
if red.Checked=True then
p1.InnerHtml="You prefer red!"
else
p1.InnerHtml="You prefer blue!"
end if
red.checked=false
blue.checked=false
End Sub
</script>

<html>
<body>

<form runat="server">
What color do you prefer?
<br />
<input id="red" type="checkbox" runat="server" /> Red
<br />
<input id="blue" type="checkbox" runat="server" /> Blue
<br />
<input type="button" value="Submit" OnServerClick="submit" runat="server"/>
<p id="p1" runat="server" />
</form>

</body>
</html>

Output Result

3.6 VALIDATION CONTROLS


Before saving the data entered by the user into a webform, we will have to
validate the data. A web form is form which is used to accept data from the user in a
web application. We will see how to use the validation controls in a webform to
perform the validations against the data entered by the user. Validation controls are
controls which help us to perform different validations on the data entered in controls
like Textbox, Listbox and radiobutton.

ASP .NET / 38
If Validation is true
Compare two
data is saved
values

Value1 If Validation fails Web SQL


error message is Server Server
displayed Database
Value2

Validate

Fig : Working of Validation controls in ASP.NET Page

Using validation controls, we can perform the following validations.


We need to check whether user has entered data in a field because the value which is
entered into this field is going to be stored in a field which cannot be NULL. Even
though, we can check this validation using a stored procedure on the Database server
side, it is always better to use validation controls to avoid round trips. Common entries
are email Ids, telephone numbers, URLs and credit card numbers.
We can add validation controls to a webform just like any other controls. For each
specific type of validation, there is a specific validation control available in the .Net
framework. The common validation controls we use in a webform are:
 RequiredFieldValidator Control - For compulsory required fields
 RegularExpressionValidator Control - For Validating expressions
 CompareValidator Control- For Comparing values
 RangeValidator control- For checking for a range of values
 ValidationSummary control- For Summarizing Validation Errors

1) Example of Compare Validator Control


<html>
<body>

<form runat="server">
<table border="0" bgcolor="#b0c4de">
<tr valign="top">
<td colspan="4"><h4>Compare two values</h4></td>
</tr>
<tr valign="top">
<td><asp:TextBox id="txt1" runat="server" /></td>
<td> = </td>
<td><asp:TextBox id="txt2" runat="server" /></td>
<td><asp:Button Text="Validate" runat="server" /></td>
</tr>
</table>
<br />
<asp:CompareValidator
id="compval"
Display="dynamic"
ControlToValidate="txt1"
ControlToCompare="txt2"
ForeColor="red"
BackColor="yellow"
Type="String"
Introduction to ASP .NET 2.0 / 39
EnableClientScript="false"
Text="Validation Failed!"
runat="server" />
</form>

</body>
</html>

Output Result :

2) Example of Range Validator control


<html>
<body>

<form runat="server">
Enter a date between 2005-01-01 and 2005-12-31:
<br />
<asp:TextBox id="tbox1" runat="server" />
<br /><br />
<asp:Button Text="Submit" runat="server" />
<br /><br />
<asp:RangeValidator
ControlToValidate="tbox1"
MinimumValue="2005-01-01"
MaximumValue="2005-12-31"
Type="Date"
EnableClientScript="false"
Text="The date must be between 2005-01-01 and 2005-12-31!"
runat="server" />
</form>

</body>
</html>

Output Result :

3.7 USER CONTROL


Server controls are one of the things that make developing with ASP.NET so
simple and powerful at the same time. We've discussed HTML and web server
controls and have showed you how to use them in your ASP.NET pages, but what if
there's not a control that does exactly what you want to do?
Like most everything in ASP.NET there's really no magic involved with server
controls. In fact, you can build your own controls and use them on your pages just like
you use the ones that ship with .NET. Controls that you build are called user controls
and they are shown below.

ASP .NET / 40
Writing Your First User Control
Actually, writing a basic user control (also sometimes called pagelets) couldn't
be much easier... most any ASP.NET page can be used as a server control. Here's a
simple example:

basic.ascx

<p>
This is a user control... really!
</p>

The customary extension given to pages meant to be used as a control. It's


not really anything special, but it does keep things easier to understand and by default
.ascx files are prevented from being directly executed and served by IIS.
Now that we've created our user control, here's a sample of how to use it in an
ASP.NET web page.
basic.aspx
<%@ Page Language="C#" %>
<%@ Register TagPrefix="asp101samps" TagName="SomeText"
Src="basic.ascx" %>

<html>
<head>
<title>ASP.NET User Control Sample - Basic</title>
</head>
<body bgcolor="#FFFFFF">
<asp101samps:SomeText runat="server" />
</body>
</html>
The above page will output a standard HTML page with the text contained in
our user control in place of the user control's tag. How does it do it? The magic here is
in the Register directive. To use it you'll need to specify three attributes:
TagPrefix : The TagPrefix attribute defines a namespace in which the control
will live. You can think of this as the world in which the control will live. Because of this,
you can have different controls with the same name and as long as they have a
different TagPrefix (and as a result different namespaces) they can peacefully co-exist
on the same page.
TagName : The TagName attribute determines the name by which the control
will be refered to. It needs to be unique within the namespace, but you can choose
whatever you like. Generally names are chosen that are indicative of what the control
actually does.
Src : The Src (or source) attribute simply specifies where the code that makes
up the control being defined is to be found. Virtual paths are used so the value should
be something like "control.ascx" or "/path/control.ascx" and not a physical path like
"C:\path\control.ascx."
Once you've added the Register directive, the control is registered and can be
used just like any other server control. You specify the TagPrefix and TagName in the
control's tag just like you would with a built in control and make sure you've got the
runat="server" attribute and you're ready to roll. Here's the basic form for a user
control's tag:
<TagPrefix:TagName runat="server" />

Giving Your Control Properties


This time around I've added two properties to the control - one to control the
color and one to control the text.

properties.ascx

<script language="VB" runat="server">


Public Color As String = "black"
Introduction to ASP .NET 2.0 / 41
Public Text As String = "This is a user control... really!"
</script>

<p>
<font color="<%= Color %>">
<%= Text %>
</font>
</p>

By default the control will look the same as before, but now we can modify the
color or text it emits either by setting properties in the control's tag or programmatically
from our code (as long as we give the control an id attribute by which to reference it).
Also note that I'm able to reuse the same control a number of times in the page and
set the properties of each instance independently.

properties.aspx

<%@ Page Language="C#" %>


<%@ Register TagPrefix="asp101samps" TagName="SomeText"
Src="properties.ascx" %>

<script language="VB" runat="server">


Sub Page_Load(Sender As Object, E As EventArgs)
UserCtrl1.Color = "green"
UserCtrl1.Text = "This control's properties were " _
& "set programmatically!"
End Sub
</script>

<html>
<head>
<title>ASP.NET User Control Sample - Properties</title>
</head>
<body bgcolor="#FFFFFF">

<asp101samps:SomeText runat="server" />

<asp101samps:SomeText Color="red" runat="server" />

<asp101samps:SomeText Text="This is quite cool!" runat="server" />

<asp101samps:SomeText Color="blue" Text="Ain't It?" runat="server" />

<asp101samps:SomeText id="UserCtrl1" runat="server" />

</body>
</html>

Having Your Control Handle Events


You can get your control to do almost anything you want it to. In the next set of
code listings the control will handle the Page_Load event all by itself. This type of
event handling allows you to write controls that need very little if any maintaining-code
to be written in the page hosting the control. The controls can handle all their own
events.
In addition, this control encapsulates an asp textbox control.

events.ascx

<script language="VB" runat="server">


Sub Page_Load(Src As Object, E As EventArgs)
Dim strInitialText As String = "Please Enter a Name!"

If Page.IsPostBack Then
If txtName.Text = strInitialText
ASP .NET / 42
txtName.Text = ""
End If
Else
txtName.Text = strInitialText
End If
End Sub

Public Property Name As String


Get
Return txtName.Text
End Get
Set
txtName.Text = Value
End Set
End Property
</script>

Name: <asp:textbox id="txtName" runat="server" />

<asp:RequiredFieldValidator ControlToValidate="txtName"
id="valtxtName" Display="Dynamic" runat=server>
Please Enter a Name!
</asp:RequiredFieldValidator>

events.aspx

<%@ Page Language="VB" ClientTarget="downlevel" %>


<%@ Register TagPrefix="asp101samps" TagName="SomeText"
Src="properties.ascx" %>
<%@ Register TagPrefix="asp101samps" TagName="TextBox"
Src="events.ascx" %>

<script language="VB" runat="server">


Sub Page_Load(Sender As Object, E As EventArgs)
txtLabel.Text = ""

' The textbox control handles its own stuff


' in its own Page_Load event handler.
End Sub

Sub btnSubmit_Click(Sender As Object, E As EventArgs)


' Sets the label to the textbox's text
txtLabel.Text = txtName.Name

' I don't need to worry about validation since


' my user control does it for me.
End Sub
</script>

<html>
<head>
<title>ASP.NET User Control Sample - Validation & Events</title>
</head>

<body bgcolor="#FFFFFF">

<form runat="server">

<asp101samps:TextBox id="txtName" runat="server" />

<br />

<asp:button id="btnSubmit" onClick="btnSubmit_Click"


Introduction to ASP .NET 2.0 / 43
text="Submit" runat="server" />

</form>

<asp101samps:SomeText id="txtLabel" runat="server" />

</body>
</html>

Check your progress 3.7


Answer the following questions in 1-2 sentences.
a) What is server control?
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…
b) Write any three server controls.
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…
c) What is validation control and user control?
…………………………………………………………………………………………..…
…………………………………………………………………………………………..…

3.8 DATA BINDING CONTROLS


Data-bound Web server controls are controls that can be bound to a data
source control to make it easy to display and modify data in your Web application.
Data-bound Web server controls are composite controls that combine other ASP.NET
Web controls, such as Label and TextBox controls, into a single layout.

The following controls are list controls which support data binding:

 asp:RadioButtonList
 asp:CheckBoxList
 asp:DropDownList
 asp:Listbox
The selectable items in each of the above controls are usually defined by one
or more asp:ListItem controls, like this:
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="countrylist" runat="server">
<asp:ListItem value="N" text="Norway" />
<asp:ListItem value="S" text="Sweden" />
<asp:ListItem value="F" text="France" />
<asp:ListItem value="I" text="Italy" />
</asp:RadioButtonList>
</form>
</body>
</html>
However, with data binding we may use a separate source, like a database,
an XML file, or a script to fill the list with selectable items. By using an imported
source, the data is separated from the HTML, and any changes to the items are made
in the separate data source.
Example of ArrayList RadioButtonList

ASP .NET / 44
<script language = “VB” runat="server">
Sub Page_Load (S as object, e As Event Args)
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
rb.DataSource=mycountries
rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)


lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>
Output Result :

3.9 CONFIGURATION
The ASP.NET configuration system features an extensible infrastructure that
enables you to define configuration settings at the time your ASP.NET applications are
first deployed so that you can add or revise configuration settings at any time with
minimal impact on operational Web applications and servers.

The ASP.NET configuration system provides the following benefits:

 Configuration information is stored in XML-based text files. Any standard text


editor or XML parser can be used to create and edit ASP.NET configuration
files.
 ASP.NET configuration settings for the entire Web server is defined in the root
configuration file named
C:\WINNT\Microsoft.NET\Framework\version\CONFIG\Machin
e.config.
 Multiple configuration files, all named Web.config, can appear in multiple
directories on an ASP.NET Web application server.
 Each Web.config file applies configuration settings to its own directory and
all child directories below it.
 Configuration files in child directories can supply configuration information in
addition to that inherited from parent directories, and the child directory
Introduction to ASP .NET 2.0 / 45
configuration settings can override or modify settings defined in parent
directories.
 At run time, ASP.NET uses the configuration information provided by the
Machine.config and all the Web.config files in a hierarchical directory
structure to compute a collection of configuration settings for each unique URL
resource. The resulting configuration settings are then cached for all
subsequent requests to a resource.
 ASP.NET detects changes to configuration files and automatically applies new
configuration settings to Web resources affected by the changes. The server
does not have to be rebooted for the changes to take effect. Hierarchical
configuration settings are automatically recalculated and recached whenever a
configuration file in the hierarchy is changed.
 The ASP.NET configuration system is extensible. You can define new
configuration parameters and write configuration section handlers to process
them.
 ASP.NET protects configuration files from outside access by configuring
Internet Information Services ( IIS ) to prevent direct browser access to
configuration files. HTTP access error 403 ( forbidden ) is returned to any
browser attempting to directly request a configuration file.
3.10 PERSONALIZATION
ASP.NET 2.0 provides specific support for personalizing Web sites. The
support ASP.NET provides for personalization service greatly simplifies the whole
management and storage of personal information. Defining a Web site's
personalization facilities begins with defining User Profiles.

3.10.1 User Profiles


The heart of the new ASP.NET personalization service is the User Profile. A
User Profile defines what kind of personal information your Web site needs. For
example, you may want to know personal data about users of your Web site, such as
name, gender, number of visits to the site, and so forth. User Profiles are also handy
for storing user preferences for your site. For example, you might include a Theme as
part of a personal profile so that users can tailor the pages to their particular tastes.
Once the personalization properties are defined in Web.Config, a component
within .NET has to be able to read it and use it. That job is handled by ASP.NET
personalization providers.

3.10.2 Personalization Providers


Providers hide the coding differences involved in creating the necessary
objects for connecting to various databases. Just pick a provider (for example, SQL
Server or Access), and the provider does the dirty work of manufacturing connections
and such. ASP.NET includes two personalization providers out of the box: a profile
provider for custom user data and a personalization provider for Web Parts.
ASP.NET defines the fundamental provider capabilities in an abstract class
named PersonalizationProvider. Those capabilities include such things as loading and
saving personalization properties and managing their relationship to any Web Parts
used within a site. ASP.NET provides a default implementation of these capabilities in
a concrete class named SqlPersonalizationProvider, which is derived from
PersonalizationProvider.

3.10.3 Using Personalization


Using personalization is pretty straightforward. You basically define
personalization properties in Web.Config. ASP.NET will synthesize a class you may
use to manage personalization settings. At that point, profile information is available in
much the same way as session state is available.
3.10.4 Defining Profiles in Web.Config

ASP .NET / 46
Profile schema is defined within Web.Config as name/type pairs. Imagine that
in the course of designing your site, you decided you'd like to track the following
information about a particular user:
 User name
 Gender
 Visit count
 Birthday
Defining these properties is a matter of populating them in Web.Config. A
definition for the properties listed above might look like this Web.Config:
<system.web>
<profile automaticSaveEnabled="true" >
<properties>
<add name="NumVisits" type="System.Int32"/>
<add name="UserName" type="System.String"/>
<add name="Gender" type="bool">
<add name="Birthday" type="System.DateTime">
</properties>
</profile>
</system.web>
The personalization properties consist of name/type pairs and will basically
become the schema under which the personalization data will be stored. Once defined
in the Web.Config file, the profile may be used in the site through the Profile property
found in the current HttpContext (and is also available via the Page).
3.10.5 Use Profile Information
To use the profile in the Web site, you access it in much the same way you
might access session state. However, instead of being represented by name/value
pairs accessed through an indexer, the ASP.NET compiler will synthesize a profile
object based upon the scheme defined in the Web.Config file.

For example, given the schema listed above, ASP.NET will synthesize a class
named ProfileCommon, based upon the ProfileBase class. The synthesized class will
reflect the instructions written into the Web.Config by inserting properties, shown here
in bold:
public class ProfileCommon : ProfileBase
{
public virtual HttpProfile GetProfile(string username);
public object GetPropertyValue(string propertyName);
public void SetPropertyValue(string propertyName,
object propertyValue);
public HttpProfileGroupBase GetProfileGroup(String groupName);
public void Initialize(String username,Boolean isAuthenticated);
public virtual void Save();
public void Initialize(SettingsContext context,
SettingsPropertyCollection properties,
SettingsProviderCollection providers);
public string UserName{get; set;};
public int NumVisits{get; set;};
public bool Gender(get; set; );
public DateTime Birthdate{get; set; };
}
To access the profile properties, simply use the Profile property within the
page. The Profile property is an instance of the Profile Common class synthesized by
ASP.NET. Just access the members of the Profile, like so:
protected void Page_Load(object sender, EventArgs e)
{
if (Profile.Name != null)
{
Introduction to ASP .NET 2.0 / 47
Response.Write("Hello " + Profile.Name);
Response.Write("Your birthday is " +
Profile.Birthdate);
}
}

3.10.6 Saving Profile Changes

The preceding code snippet assumes there's already personalization


information associated with the user. To insert profile data for a particular user, simply
set the properties of the Profile object. For example, imagine a page that includes a
handler for saving the profile. It might look something like this:
protected void ProfileSaveClicked(object sender, EventArgs e)
{
Profile.Name = this.TextBoxName.Text;
Profile.Birthdate = this.Calendar1.SelectedDate;
}
The easiest way to ensure that the personalization properties persist is to set
the automaticSaveEnabled to true. Personal profile data will be saved automatically by
the provider. Alternatively, you may call Profile.Save as necessary to save the
personalization properties. In addition to saving and loading profiles, you may also
delete the profile for a specific user by calling Profile.DeleteProfile.
3.10.7 Profiles and Users

Profile information is associated with the current user based upon the identity
of the user. By default, ASP.NET uses the User.Identity.Name within the current
HttpContext as the key to store data. By default, profiles are available only for
authenticated users.
ASP.NET supports anonymous profiles as well. Turn this on within
Web.Config. The default tracking mechanism for anonymous profiles is to use cookies.
However, as with tracking session state, you may tell ASP.NET to use a mangled
URL.
The following exercise illustrates using personalization profiles based on the
user's login ID.
Using Profiles
1. Create a new project. Name the project MakeItPersonal.
2. Add a Web.Config file to the project. Update Web.Config to include some
profile properties. The example here includes a user name, a Theme, and a
birth date. Be sure to turn anonymous Identification to true. The following
example shows that you may group and nest profile structures using the
<group> element.
<system.web>

<profile>
<properties >
<add name="Theme" type="System.String"/>
<add name="Name" type="String"/>
<add name="Birthdate"" type="System.DateTime"/>
<group name="Address">
<add name="StreetAddress"/>
<add name="City"/>
<add name="State"/>
<add name="ZipCode"/>
</group>
</properties>
</profile>

</system.web>
1. Borrow the Default and SeeingRed Themes from the MasterPagesSite project.
This will let the user pick the Theme.
2. Borrow the UseThemes.aspx and .cs files from the MasterPagesSite project.
3. Borrow the Banner.ascx file from the MasterPagesSite.

ASP .NET / 48
4. Now update the Default.aspx page. This will be where users type profile
information. Add text boxes for the name, address, city, state, and zip code.
Add a drop-down list box populated with Default and SeeingRed items. This
will be used for selecting the Theme. Also add a calendar control to pick the
birthdate.
5. Add a button the user may click to submit profile information. Add a handler to
input these values into the profile. Double-click on the button to add the
handler.
The input screen should look something like this:

6. Update Page_Load to display profile information (if it's there). Grab the profile
object and set each of the text boxes and the calendar control.

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)

{
ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);
if (pc != null)
{
this.TextBoxName.Text = pc.Name;
this.TextBoxAddress.Text = pc.Address.StreetAddress;
this.TextBoxCity.Text = pc.Address.City;
this.TextBoxState.Text = pc.Address.State;
this.TextBoxZipCode.Text = pc.Address.ZipCode;
this.DropDownList1.SelectedValue = pc.Theme;
this.Calendar1.SelectedDate = pc.Birthdate;
}
}
}
// …
}

7. Update the profile submission handler to store the profile information.

protected void ButtonSubmitProfile_Click(object sender, EventArgs e)


Introduction to ASP .NET 2.0 / 49
{

ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);

if (pc != null)
{
pc.Name = this.TextBoxName.Text;
pc.Address.StreetAddress = this.TextBoxAddress.Text;
pc.Address.City = this.TextBoxCity.Text;
pc.Address.State = this.TextBoxState.Text;
pc.Address.ZipCode = this.TextBoxZipCode.Text;
pc.Theme = this.DropDownList1.SelectedValue;
pc.Birthdate = this.Calendar1.SelectedDate;

pc.Save();
}
}

8. Finally, update the UseThemes.aspx page to use the Theme. Override the
page's OnPreInit method. Have the code apply the Theme as specified by the
profile.

protected override void OnPreInit(EventArgs e)


{
ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);
if (pc != null)
{
String strTheme = pc.Theme.ToString();
if (strTheme != null &&
strTheme.Length > 0)
{
this.Theme = strTheme;
}
}
base.OnPreInit(e)
}

9. When you surf to the page, you should be able to enter the profile information
and submit it. Following your initial visit, the profile will be available whenever
you hit the site.

3.11 SESSION STATE


ASP.NET session state enables you to store and retrieve values for a user as
the user navigates ASP.NET pages in a Web application.
What is session state?
A session is defined as the period of time that a unique user interacts with a
Web application. Session state is a collection of objects, tied to a session are stored
on a server.
A session is defined as the period of time that a unique user interacts with a
Web application. Active Server Pages (ASP) developers who wish to retain data for
unique user sessions can use an intrinsic feature known as session state.
Programmatically, session state is nothing more than memory in the shape of
a dictionary or hash table, e.g. key-value pairs, which can be set and read for the
duration of a user's session. For example, a user selects stocks to track and the Web
application can store these values in the user's ASP session instance:
Session("Stocks") = "MSFT; VRSN; GE"
On subsequent pages these values are read and the Web application has
access to these values without the user re-entering them:

' Get Stocks, split string, etc.


String StockString
ASP .NET / 50
StockString = Session("Stocks")

ASP maintains session state by providing the client with a unique key
assigned to the user when the session begins. This key is stored in an HTTP cookie
that the client sends to the server on each request. The server can then read the key
from the cookie and re-inflate the server session state.

ASP.NET Session State


 Process independent. ASP.NET session state is able to run in a separate
process from the ASP.NET host process. If session state is in a separate
process, the ASP.NET process can come and go while the session state
process remains available. Of course, you can still use session state in
process similar to classic ASP, too.
 Support for server farm configurations. By moving to an out-of-process
model, ASP.NET also solves the server farm problem. The new out-of-process
model allows all servers in the farm to share a session state process. You can
implement this by changing the ASP.NET configuration to point to a common
server.
 Cookie independent. Although solutions to the problem of cookie less state
management do exist for classic ASP, they're not trivial to implement.
ASP.NET, on the other hand, reduces the complexities of cookie less session
state to a simple configuration setting.
Let's look at each of these features in more detail, including how the settings
are configured.

Using ASP.NET Session State


Session state settings in ASP.NET are configured through the ASP.NET XML
configuration file config.web. We'll look at config.web in more detail in a later column,
but for this discussion of session state let's look at it briefly.

Config.web
There are two types of configuration files: a machine configuration file and an
application configuration file, both named config.web. The two are identical, except
that the machine configuration file applies settings to all applications but the
application configuration files are either restrictive or expansive on an application-by-
application basis.
The machine config.web file is in the WinNT\Microsoft.NET\Framework\v1.0.2204
directory, while the optional application configuration files exist in the application's
directory. Application config.web files are optional in the sense that if an application
config.web file doesn't exist, the machine config.web settings are used instead.
ASP.NET session state settings can be made in the machine config.web file and
overridden in a particular application's config.web file.

Session configuration
Below is a sample config.web file used to configure the session state settings for an
ASP.NET application:
<configuration>
<sessionstate
mode="inproc"
cookieless="false"
timeout="20"
sqlconnectionstring="data source=127.0.0.1;user id=<user
id>;password=<password>"
server="127.0.0.1"
port="42424"
/>
</configuration>

Introduction to ASP .NET 2.0 / 51


The settings above are used to configure ASP.NET session state. Let's look at each in
more detail and cover the various uses afterward.
 Mode. The mode setting supports three options: inproc, sqlserver, and
stateserver. As stated earlier, ASP.NET supports two modes: in process and
out of process. There are also two options for out-of-process state
management: memory based (stateserver), and SQL Server based
(sqlserver). We'll discuss implementing these options shortly.
 Cookieless. The cookieless option for ASP.NET is configured with this simple
Boolean setting.
 Timeout. This option controls the length of time a session is considered valid.
The session timeout is a sliding value; on each request the timeout period is
set to the current time plus the timeout value
 Sqlconnectionstring. The sqlconnectionstring identifies the database
connection string that names the database used for mode sqlserver.
 Server. In the out-of-process mode stateserver, it names the server that is
running the required Windows NT service: ASPState.
 Port. The port setting, which accompanies the server setting, identifies the
port number that corresponds to the server setting for mode stateserver.

Sample session state application

Before we use session state, we need an application to test it with. Below is


the code for a simple Visual Basic application that writes to and reads from session
state, SessionState.aspx:
<Script language = “VB” runat=”server”>
Sub Session_Add(sender As Object, e As EventArgs)
Session("MySession") = text1.Value
span1.InnerHtml = "Session data updated! <P>
Your session contains: <font color=red>" +
Session("MySession").ToString() + "</font>"
End Sub

Sub CheckSession(sender As Object, e As EventArgs)


If (Session("MySession") = Isnull) Then
span1.InnerHtml = "NOTHING, SESSION DATA LOST!"
Else
span1.InnerHtml = "Your session contains:
<font color=red>" +
Session("MySession").ToString() + "</font>"
End If
End Sub
</Script>

<form runat=server>
<input id=text1 type=text runat=server>
<input type=submit runat=server
OnServerClick="Session_Add" Value="Add to Session State">
<input type=submit runat=server
OnServerClick="CheckSession" Value="View Session State">
</form>
<hr size=1>
<font size=6><span id=span1 runat=server/></font>

This simple page wires up two server-side events for the Add and View buttons, and
simply sets the session state to the value in the text box.

3.12 SUMMARY

 ASP.NET is the latest version of Microsoft's Active Server Pages technology


(ASP). ASP.NET is a server side scripting technology that enables scripts to be
executed by an Internet server.
ASP .NET / 52
 A master page is a template for other pages, with shared layout and
functionality. The master page defines placeholders for content pages.

 Web Forms Page Life Cycle for a Web Forms page is similar to that of any Web
process that runs on the server. Certain characteristics of Web
processing information is passed through HTTP protocol, the stateless nature of
Web pages, the ASP.NET page framework performs many Web application
services for us. It is important to understand the sequence of events that occur
when a Web Forms page is processed.

 ASP.NET server controls are objects and have their own properties, methods
and event handlers. HTML elements in ASP.NET files are, by default, treated as
text. To make these elements programmable, add a runat ="server" attribute to
the HTML element. This attribute indicates that the element should be treated as
a server control.

 The support ASP.NET provides for personalization service greatly simplifies the
whole management and storage of personal information. Defining a Web site's
personalization facilities begins with defining User Profiles.

 A session is defined as the period of time that a unique user interacts with a
Web application. Session state is a collection of objects, tied to a session are
stored on a server.

Check your progress 3.11


Answer the following questions in 1-2 sentence\cues.
a) What is ASP.net configuration?
……………………………………………………………………………………………………
……………………………………………………………………………………………………
b) What is personalization in ASP.net?
……………………………………………………………………………………………………
……………………………………………………………………………………………………
c) What is session state?
……………………………………………………………………………………………………
……………………………………………………………………………………………………

3.13 CHECK YOUR PROGRESS -ANSWERS


3.2
1. It is a server side scripting language, means complete code get run on server
and result get back in HTML format to client.
2. Master page, themes, role, personalization, new ado.net features, XML standard
support etc.
3.3
1. Web form life cycle refers to the tenure of page in server from initiating to out it
consist of : -
Page request  Start  Page initialization  Load  Validation  Post back
event handling  Rendering  Unload.
3.4 - 3.7
1. Server Control runs on server side, they have their own property, they retain
their value during subsequent request.
2. Validation control are for defined control which validate the userdata entering in
a webpage. Ex. Required field Validator user control is a type of composite
control which works like other ASP Control, but the basic difference is that

Introduction to ASP .NET 2.0 / 53


control are designed by user itself. Ex. Combination of textbox and command
button.
3.8 – 3.11
1. It is the configuration defined at the time we host our WebPages and it is stored
in web.config file.
2. Personalization is a process where we personalize a web page according to
user, which include language, common page etc.
3. Session state is a time define that how long a user connected to a page or could
be able to connect that page. Ex. Your email session expires in 5 min ideal time.
3.14 QUESTIONS FOR SELF - STUDY
1. Explain Life Cycle of a Web Forms Page with diagram.
2. Explain Dropdown List Server Control with example.
3. What is Validation controls explain with example?
4. Explain the benefits of configuration.

3.15 SUGGESTED READINGS

1. Programming C#: Building .NET Applications with C# By Jesse Liberty


2. Learning C# 2005 by Jesse Liberty
3. Microsoft MSDN
4. http://netservicesindia.com/blog/?p=35
5. https://en.wikipedia.org/wiki/ASP.NET
6. http://www.zeali.net/mirrors/w3cshool/aspnet/aspnet_newfeatures.asp.html
7. http://www.w3schools.com/aspnet/aspnet_arraylist.asp



ASP .NET / 54

You might also like