Advanced Study Material for Computer Science: .NET Technology
Explore structured advanced study materials through the Application of .NET Technology Unit 05 ASP.NET 2.0 Notes Set 02. Tailored for learners, utilizing these Computer Science resources ensures thorough preparation and strengthens foundational knowledge before final evaluations.
Practice Computer Science Resources: .NET Technology
Navigate directly to the advanced Computer Science study materials using the digital viewer below. Each resource pack includes detailed conceptual summaries and solved practice questions, allowing students to instantly reinforce their learning.
This page covers the properties common to all ASP.NET server controls, the standard control categories and HTML server controls with a full code listing, followed by the validation controls and their properties, user controls and data binding. It ends with web.config configuration, profile-based personalization, session state, global.asa events, cookies and the ADO.NET classes.
Properties for all controls
If you look at the Properties Grid for some of the controls in a page, you'll notice that many of them have similar properties.
| Property | Description |
|---|---|
| AccessKey | Enables you to set a key with which a control can be accessed at the client by pressing the associated letter. |
| BackColor, ForeColor | Enables you to change the color of the background (BackColor) and text (ForeColor) of the control. |
| BorderColor, BorderStyle, BorderWidth | Changes the border of the control in the browser. The similarities with the CSS border properties are no coincidence. Each of these three ASP.NET properties maps directly to its CSS counterpart. |
| CssClass | Lets you define the HTML class attribute for the control in the browser. This class name then points to a CSS class you defined in the page or an external CSS file. |
| Enabled | Determines whether the user can interact with the control in the browser. For example, with a disabled text box (Enabled="False") you cannot change its text. |
| Font | Enables you to define different font-related settings, such as Font-Size, Font-Names, and Font-Bold. |
| Height, Width | Determines the height and width of the control in the browser. |
| TabIndex | Sets the client-side HTML tabindex attribute that determines the order in which users can move through the controls in the page by pressing the Tab key. |
| ToolTip | Enables you to set a tooltip for the control in the browser. This tooltip, rendered as a title attribute in the HTML, is shown when the user hovers the mouse over the relevant HTML element. |
| Visible | Determines whether or not the control is sent to the browser. You should really see this as a server-side visibility setting because an invisible control is never sent to the browser at all. This means it's quite different from the CSS display and visibility properties that hide the element at the client. |
Types of Controls
1. ASP.NET comes with a large number of server controls, supporting most of your web development needs.
2. To make it easy for you to find the right controls, they have been placed in separate control categories in the Visual Web Developer Toolbox.
3. For example, a TextBox has a Text property (among many others), and a ListBox has a SelectedItem property.
4. Some properties can only be set programmatically and not with the Properties Grid.
Standard Controls
The Standard category contains many of the basic controls that almost any web page needs. You've already seen some of them, like the TextBox, Button, and Label controls earlier in this chapter. Many of the controls probably speak for themselves, so instead of giving you a detailed description of them all, the following sections briefly highlight a few important ones.
Simple Controls
The Toolbox contains a number of simple and straightforward controls, including TextBox, Button, Label, HyperLink, RadioButton, and CheckBox. Their icons in the Toolbox give you a good clue as to how they end up in the browser.
List Controls
1. The standard category also contains a number of controls that present themselves as lists in the browser. These controls include ListBox, DropDownList, CheckBoxList, RadioButtonList, and BulletedList.
2. To add items to the list, you define <asp:ListItem> elements between the opening and closing tags of the control.
<asp:DropDownList ID="FavoriteLanguage" runat="server"> <asp:ListItem Value="C#">C#</asp:ListItem> <asp:ListItem Value="Visual Basic">Visual Basic</asp:ListItem> <asp:ListItem Value="CSS">CSS</asp:ListItem> </asp:DropDownList>
1. The DropDownList enables a user to select only one item at a time.
2. To see the currently active and selected item of a list control programmatically, you can look at its SelectedValue, SelectedItem, or SelectedIndex properties.
3. SelectedValue returns a string that contains the value for the selected item, like C# or Visual Basic in the preceding example.
4. SelectedIndex returns the zero-based index of the item in the list. With the preceding example, if the user had chosen C#, SelectedIndex would be 0. Similarly, when the user has chosen CSS, the index would be 2 (the third item in the list).
5. The BulletedList control doesn't allow a user to make selections, and as such doesn't support these properties.
6. For controls that allow multiple selections (like CheckBoxList and ListBox), you can loop through the Items collection and see what items are selected. In this case, SelectedItem returns only the first selected item in the list; not all of them.
Container Controls
1. Controls can be grouped by putting them in one of the container controls, like the Panel, the PlaceHolder, the MultiView, or the Wizard.
2. For example, you can use the PlaceHolder or the Panel control to hide or show a number of controls at once.
3. Instead of hiding each control separately, you simply hide the entire container that contains all the individual controls and markup.
LinkButton and ImageButton
1. The LinkButton and the ImageButton controls operate similarly to an ordinary Button control. Both of them cause a postback to the server when they are clicked.
2. The LinkButton presents itself as a simple <a> element but posts back (using JavaScript) instead of requesting a new page.
3. The ImageButton does the same, but displays an image that the user can click to trigger the postback.
Image and ImageMap
1. These controls are pretty similar in that they display an image in the browser.
2. The ImageMap enables you to define hotspots on the image that when clicked either cause a postback to the server or navigate to a different page.
Calendar
The Calendar control presents a rich interface that enables a user to select a date.
FileUpload
The FileUpload control enables a user to upload files that can be stored on the server.
Literal, Localize, and Substitute
1. The Literal control renders no additional tag itself; it displays only what you assign to its Text property and is thus very useful to display HTML or JavaScript that you build up in the Code Behind or that you retrieve from a database.
2. The Localize control is used in multilingual web sites and is able to retrieve its contents from translated resource files.
3. The Substitute control is used in advanced caching scenarios and enables you to update only parts of a page that is otherwise cached completely.
AdRotator
1. The AdRotator control enables you to display random advertisements on your web site. The ads come from an XML file that you create on your server.
2. Because it lacks advanced features like click tracking and logging that are required in most but the simplest scenarios, this control isn't used much in today's web sites.
HiddenField
1. The HiddenField control enables you to store data in the page that is submitted with each request.
2. This is useful if you want the page to remember specific data without the user seeing it on the page.
XML
The XML control enables you to transform data from an XML format to another format (like XHTML) for display on a page.
Table
1. The <asp:Table> control is in many respects identical to its HTML <table> counterpart.
2. However, because the control lives at the server, you can program against it, dynamically creating new columns and rows and adding dynamic data to it.
HTML Control
1. The HTML category of the Toolbox contains a number of HTML controls that look similar to the ones found in the Standard category.
2. For example, you find the Input (Button) that looks like the <asp:Button>. Similarly, there is a Select control that has the <asp:DropDownList> and <asp:ListBox> as its counterparts.
3. The HTML server controls are basically the original HTML controls but enhanced to enable server side processing.
4. The HTML controls like the header tags, anchor tags and input elements are not processed by the server but sent to the browser for display.
5. They are specifically converted to a server control by adding the attribute runat="server" and adding an id attribute to make them available for server-side processing.
6. For example, consider the HTML input control:
<input type="text" size="40">
It could be converted to a server control, by adding the runat and id attribute:
<input type="text" id="testtext" size="40" runat="server">
Advantages of using HTML Server Controls
| Control Name | HTML tag |
|---|---|
| HtmlHead | <head> element |
| HtmlInputButton | <input type=button|submit|reset> |
| HtmlInputCheckbox | <input type=checkbox> |
| HtmlInputFile | <input type=file> |
| HtmlInputHidden | <input type=hidden> |
| HtmlInputImage | <input type=image> |
| HtmlInputPassword | <input type=password> |
| HtmlInputRadioButton | <input type=radio> |
| HtmlInputReset | <input type=reset> |
| HtmlText | <input type=text|password> |
| HtmlImage | <img> element |
| HtmlLink | <link> element |
| HtmlAnchor | <a> element |
| HtmlButton | <button> element |
| HtmlForm | <form> element |
| HtmlTable | <table> element |
| HtmlTableCell | <td> element |
| HtmlTableRow | <tr> element |
| HtmlTitle | <title> element |
| HtmlSelect | <select> element |
| HtmlGenericControl | All HTML controls not listed |
Although ASP.NET server controls can perform every job accomplished by the HTML server controls, the latter controls are useful in the following cases:
1. Using static tables for layout purposes.
2. Converting a HTML page to run under ASP.NET.
Example for HTML control
The following example uses a basic HTML table for layout. It uses some text boxes for getting input from the users like name, address, city, state etc. It also has a button control, which is clicked to get the user data displayed on the last row of the table.
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="htmlserver._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 156px;
}
.style2
{
width: 332px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 54%;">
<tr>
<td class="style1">Name:</td>
<td class="style2">
<asp:TextBox ID="txtname" runat="server" style="width:230px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">Street</td>
<td class="style2">
<asp:TextBox ID="txtstreet" runat="server" style="width:230px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">City</td>
<td class="style2">
<asp:TextBox ID="txtcity" runat="server" style="width:230px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">State</td>
<td class="style2">
<asp:TextBox ID="txtstate" runat="server" style="width:230px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="style1"> </td>
<td class="style2"></td>
</tr>
<tr>
<td class="style1"></td>
<td ID="displayrow" runat="server" class="style2">
</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Click" />
</form>
</body>
</html>The code behind the button control
protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
str += txtname.Text + "<br />";
str += txtstreet.Text + "<br />";
str += txtcity.Text + "<br />";
str += txtstate.Text + "<br />";
displayrow.InnerHtml = str;
}Observe the following:
1. The normal HTML tags have been used for the page layout.
2. The last row of the HTML table is used for data display.
3. It needed server side processing, so an ID attribute and the runat attribute have been added to it.
Validation Control
1. ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated or contradictory data don't get stored.
2. ASP.NET provides the following validation controls: BaseValidator, RequiredFieldValidator, RangeValidator, CompareValidator, RegularExpressionValidator, CustomValidator and ValidationSummary.
The BaseValidator Class
The validation control classes inherit from the BaseValidator class and inherit its properties and methods. Therefore, it would help to take a look at the properties and the methods of this base class, which are common for all the validation controls:
| Members | Description |
|---|---|
| ControlToValidate | Indicates the input control to validate. |
| Display | Indicates how the error message is shown. |
| EnableClientScript | Indicates whether client side validation will take place. |
| Enabled | Enables or disables the validator. |
| ErrorMessage | Indicates error string. |
| Text | Error text to be shown if validation fails. |
| IsValid | Indicates whether the value of the control is valid. |
| SetFocusOnError | It indicates whether in case of an invalid control, the focus should switch to the related input control. |
| ValidationGroup | The logical group of multiple validators, where this control belongs. |
| Validate() | This method revalidates the control and updates the IsValid property. |
The RequiredFieldValidator
1. The RequiredFieldValidator control ensures that the required field is not empty.
2. It is generally tied to a text box to force input into the text box.
3. It is useful to validate whether the user filled the required text box or not; if not, the error message would be displayed.
4. The syntax for the control:
<asp:RequiredFieldValidator ID="rfvcandidate"
runat="server" ControlToValidate="ddlcandidate"
ErrorMessage="Please choose a candidate"
InitialValue="Please choose a candidate">
</asp:RequiredFieldValidator>The RangeValidator
The RangeValidator control verifies that the input value falls within a predetermined range. It has three specific properties:
| Properties | Description |
|---|---|
| Type | It defines the type of the data; the available values are: Currency, Date, Double, Integer and String. |
| MinimumValue | It specifies the minimum value of the range. |
| MaximumValue | It specifies the maximum value of the range. |
The basic example for the control:
<asp:RangeValidator ID="rvclass"
runat="server"
ControlToValidate="txtclass"
ErrorMessage="Enter your class (6 - 12)"
MaximumValue="12"
MinimumValue="6" Type="Integer">
</asp:RangeValidator>The CompareValidator
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 input control to compare with. |
| ValueToCompare | It specifies the constant value to compare with. |
| Operator | It specifies the comparison operator, the available values are: Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual and DataTypeCheck. |
The basic syntax for the control:
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator">
</asp:CompareValidator>The RegularExpressionValidator
1. The RegularExpressionValidator allows validating the input text by matching it against a pattern given as a regular expression.
2. The regular expression is set in the ValidationExpression property.
3. The following table summarizes the metacharacters used in regular expressions:
| Metacharacters | Description |
|---|---|
| . | Matches any character except \n. |
| [abcd] | Matches any character in the set. |
| [^abcd] | Excludes any character in the set. |
| [2-7a-mA-M] | Matches any character specified in the range. |
| \w | Matches any alphanumeric character and underscore. |
| \W | Matches any non-word character. |
| \s | Matches whitespace characters like space, tab, new line etc. |
| \S | Matches any non-whitespace character. |
| \d | Matches any decimal character. |
| \D | Matches any non-decimal character. |
The following quantifiers are used in the regular expression for matching the input text:
| Quantifier | Description |
|---|---|
| * | Zero or more matches. |
| + | One or more matches. |
| ? | Zero or one matches. |
| {N} | N matches. |
| {N,} | N or more matches. |
| {N,M} | Between N and M matches. |
The syntax for the control:
<asp:RegularExpressionValidator ID="string" runat="server" ErrorMessage="string"
ValidationExpression="string" ValidationGroup="string">
</asp:RegularExpressionValidator>The CustomValidator
1. The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation.
2. The client side validation is accomplished through the ClientValidationFunction property.
3. The client side validation routine should be written in a scripting language, like JavaScript or VBScript, which the browser can understand.
4. The basic syntax for the control:
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="cvf_func"
ErrorMessage="CustomValidator">
</asp:CustomValidator>The ValidationSummary
The ValidationSummary control displays a report of all validation errors in the page. The basic syntax for the control:
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode="BulletList" ShowSummary="true" HeaderText="Errors:" />User Controls
1. A user control is a reusable piece of markup and code that can be used on many pages of a web site, so a small change made in the user control is reflected everywhere it is used.
2. User controls behave like miniature ASP.NET pages, or web forms, which could be used by many other pages.
3. These are derived from the System.Web.UI.UserControl class. These controls have the following characteristics:
1. They have an .ascx extension.
2. They may not contain any <html>, <body> or <form> tags.
3. They have a Control directive instead of a Page directive.
To understand the concept let us create a simple user control, which will work as footer for the web pages. To create and use the user control, take the following steps:
1. Create a new web application.
2. Right click on the project folder on the Solution Explorer and choose Add New Item.
Exposing User Control Properties
1. When a Web Forms page is treated as a control, the public fields and methods of that Web Form are promoted to public properties and methods of the control as well.
2. The following example shows an extension of the previous user control example that adds two public String fields.
<%@ Register TagPrefix="Acme" TagName="Message" Src="userctrl2_vb.ascx" %>
<html>
<script language="VB" runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
MyMessage.MessageText = "Message text changed!"
MyMessage.Color = "red"
End Sub
</script>
<body style="font: 10pt verdana">
<h3>A Simple User Control w/ Properties</h3>
<form runat="server">
<Acme:Message Id="MyMessage" MessageText="This is a custom message!"
Color="blue" runat="server"/>
<p>
<asp:button text="Change Properties" OnClick="SubmitBtn_Click" runat="server"/>
</form>
</body>
</html>1. The public properties and methods are treated as public fields when promoted to a public control.
2. Notice that these fields can be set either declaratively or programmatically in the containing page.
Data Binding Control
1. Every ASP.NET web form control inherits the DataBind method from its parent Control class, which gives it an inherent capability to bind data to at least one of its properties.
2. This is known as simple data binding or inline data binding.
3. Simple data binding involves attaching any collection (item collection) which implements the IEnumerable interface, or the DataSet and DataTable classes to the DataSource property of the control.
4. On the other hand, some controls can bind records, lists, or columns of data into their structure through a DataSource control. These controls derive from the BaseDataBoundControl class. This is called declarative data binding.
5. The data source controls help the data-bound controls implement functionalities like sorting, paging and editing data collections.
6. The BaseDataBoundControl is an abstract class, which is inherited by two more abstract classes: DataBoundControl and HierarchicalDataBoundControl.
7. The abstract class DataBoundControl is again inherited by two more abstract classes: ListControl and CompositeDataBoundControl.
8. The controls capable of simple data binding are derived from the ListControl abstract class and these controls are: BulletedList, CheckBoxList, DropDownList, ListBox and RadioButtonList.
9. The controls capable of declarative data binding are derived from the abstract class CompositeDataBoundControl. These controls are: DetailsView, FormView, GridView and RecordList.
Simple Data Binding
1. Simple data binding involves the read-only selection lists. These controls can bind to an array list or fields from a database.
2. Selection lists take two values from the database or the data source; one value is displayed by the list and the other is considered as the value corresponding to the display.
3. Choosing a data source for the bulleted list control involves: selecting the data source control, selecting a field to display (which is called the data field) and selecting a field for the value.
Declarative Data Binding
1. Declarative data binding was used earlier with the GridView control.
2. The other composite data bound controls capable of displaying and manipulating data in a tabular manner are the DetailsView, FormView and RecordList controls.
3. However, the data binding involves the following objects:
1. A dataset that stores the data retrieved from the database.
2. The data provider, which retrieves data from the database, using a command over a connection.
3. The data adapter that issues the select statement stored in the command object; it is also capable of updating the data in a database by issuing Insert, Delete, and Update statements.
Configuration
1. The behavior of an ASP.NET application is affected by different settings in the configuration files: machine.config and web.config.
2. The machine.config file contains default and the machine-specific value for all supported settings.
3. The machine settings are controlled by the system administrator and applications are generally not given access to this file.
4. An application however, can override the default values by creating web.config files in its root folder.
5. The web.config file is a subset of the machine.config file.
6. If the application contains child directories, it can define a web.config file for each folder. Scope of each configuration file is determined in a hierarchical top-down manner.
7. Any web.config file can locally extend, restrict, or override any settings defined on the upper level.
8. Visual Studio generates a default web.config file for each project.
9. An application can execute without a web.config file, however, you cannot debug an application without a web.config file.
10. The web.config file has the configuration element as the root node. Information inside this element is grouped into two main areas: the configuration section-handler declaration area, and the configuration section settings area.
Configuration Section Handler
1. The configuration section handlers are contained within the <configSections> tags.
2. Each configuration handler specifies name of a configuration section, contained within the file, which provides some configuration data.
| Element | Description |
|---|---|
| Clear | It removes all references to inherited sections and section groups. |
| Remove | It removes a reference to an inherited section and section group. |
| Section | It defines an association between a configuration section handler and a configuration element. |
| Section group | It defines an association between a configuration section handler and a configuration section. |
Other configuration settings
| Setting | Description |
|---|---|
| Application settings | The application settings allow storing application-wide name-value pairs for read-only access. |
| The connection strings | The connection strings show which database connection strings are available to the website. |
| System.web Element | The system.web element specifies the root element for the ASP.NET configuration section and contains configuration elements that configure ASP.NET Web applications and control how the applications behave. It holds most of the configuration elements needed to be adjusted in common applications. |
Anonymous Identification
| Element | Description |
|---|---|
| Anonymous Identification | This is required to identify users who are not authenticated when authorization is required. |
| Authentication | It configures the authentication support. |
| Authorization | It configures the authorization support. |
| UrlMappings | Defines the mappings for hiding the actual URL and providing a more user friendly URL. |
Personalization
1. ASP.NET personalization service is based on user profile.
2. User profile defines the kind of information about the user that the site will need, for example, name, age, address, date of birth, phone number etc.
3. Web sites are designed for repeated visits from the users.
4. Personalization allows a site to remember its user and his/her information details and presents an individualistic environment to each user.
5. ASP.NET provides services for personalizing a web site to suit a particular client's taste and preference.
6. This information is defined in the web.config file of the application and ASP.NET runtime reads and uses it. This job is done by the personalization providers.
7. The user profiles obtained from user data is stored in a default database created by ASP.NET. You can create your own database for storing profiles.
8. The profile data definition is stored in the configuration file web.config.
Example
1. Let us create a sample site, where we want our application to remember user details like name, address, date of birth etc.
2. Add the profile details in the web.config file within the <system.web> element.
3. When the profile is defined in the web.config file, the profile could be used through the Profile property found in the current HttpContext and also available via page.
4. Add the text boxes to take the user input as defined in the profile and add a button for submitting the data.
Attributes for the <add> Element
Apart from the name and type attributes, there are other attributes to the <add> element. The following table illustrates some of these attributes:
| Attributes | Description |
|---|---|
| name | The name of the property. |
| type | By default the type is string but it allows any fully qualified class name as data type. |
| serializeAs | The format to use when serializing this value. |
| readOnly | A read only profile value cannot be changed, by default this property is false. |
| defaultValue | A default value that is used if the profile does not exist or does not have information. |
| allowAnonymous | A Boolean value indicating whether this property can be used with the anonymous profiles. |
| Provider | The profiles provider that should be used to manage just this property. |
Session State
1. Session and application variables are an important part of ASP programming.
2. Whether it's developing simple hit counters or developing advanced chat servers, session and application variables are a must have feature of many applications.
3. To try them out you need a web server (IIS or PWS) capable of running ASP scripts, and basic knowledge of ASP.
Session Object
1. The session object is used to store variables for each specific visitor to your web site.
2. These variables could represent anything from how many pages the user has viewed to their login details.
3. A session is defined as the time from when the user visits your site to the time when he leaves. Session variables die after a visitor closes their web browser (i.e. they are not persistent).
4. Variables stored in the session object are available to all ASP pages on that particular web site.
5. Common information stored in session variables includes name, id, and personalization preferences.
6. The server creates a new session object for each new user and destroys the session object when the session expires.
7. A session object is specific for every user and varies from user to user.
8. IIS will maintain these variables when the client moves across pages within the site.
Properties
| Property | Description |
|---|---|
| SessionID | A long number that returns the session identifier for this client. |
| Timeout | An integer that specifies a timeout period in minutes. If the client doesn't refresh or request any page from your site within this timeout period then the server ends the current session. If you do not specify any timeout period then the default timeout period of 20 minutes is used. |
Methods and events
| Name | Description |
|---|---|
| Abandon (method) | Destroys the current session object and releases its resources, meaning that if the client requests any page from your site after the Session.Abandon method has been called then a new session will be started. |
| Session_OnEnd (event) | This event occurs when the session is abandoned or times out for a specific user. |
| Session_OnStart (event) | Occurs when a new session is started. All ASP objects are available for you to use. You can define your session wide variables here. |
Example
1. You can store any value you like in the session object.
2. Information stored in the session object is available for the entire session and has "session scope".
3. The following script demonstrates how two types of variables are stored:
Session("username") = "Janine"
Session("age") = 42Application Object
1. The Application object is used to store variables and to access variables from any page.
2. All users share one Application object.
Syntax
Application.method
| Method | Description |
|---|---|
| Lock | Prevents other users from changing the application object's properties. |
| Unlock | Allows other users to change the application object's properties. |
| Event | Description |
|---|---|
| Application_OnEnd | This routine is called when all user sessions expire and the application quits. This event lives in the global.asa file, which we will look at shortly. |
| Application_OnStart | This routine is called when the application object is first referenced. This event lives in the global.asa file as well. |
The Global.asa File
1. In the global.asa file you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends.
2. The code for this is placed into event handlers.
3. Types of events: Application_OnStart, Session_OnStart, Session_OnEnd and Application_OnEnd.
| Event | When it occurs |
|---|---|
| Application_OnStart | This event occurs when the FIRST user calls the first page from an ASP application. This event also occurs after the web server is restarted or after the global.asa file is edited. When this procedure is complete, the "Session_OnStart" procedure runs. |
| Session_OnStart | This event occurs EVERY time a user visits your web site and requests the first page. |
| Session_OnEnd | This event occurs EVERY time a user ends a session. A user ends a session after a page has not been requested by the user for a specific amount of time. |
| Application_OnEnd | This event occurs after the LAST user has ended the session. Typically, this event occurs when a web server is stopped/restarted. This procedure is used to clean up settings after the application stops, such as deleting records or writing log information to text files. |
Maintaining Client State with Cookies
1. If a visitor comes to your site and types his name into a form then you might want to remember that information.
2. You may only want to remember it for his current visit (session), or for all subsequent visits for personalization (i.e. "Welcome back Mike").
3. The term state describes all client browser data for the session.
4. ASP uses client browser side cookies to remember (or persist) this data.
5. Cookies are small text files stored on the visitor's PC, usually in the Temporary Internet Files folder of Windows, in a file named Cookie:user_name@Host_Name.
6. These text files are editable with Notepad or Microsoft Word.
7. Two types of information are stored in the cookie files: Client Data and Unique Cookie ID.
| Information | Description |
|---|---|
| Client Data | The variables that make up the cookie for the visitor. These are stored as name/value pairs, such as name=john. |
| Unique Cookie ID | This allows the ASP Session to identify the client browser on a page to page and visit to visit basis. |
ADO.NET
1. ADO.NET provides a bridge between the front end controls and the back end database.
2. The ADO.NET objects encapsulate all the data access operations and the controls interact with these objects to display data, thus hiding the details of movement of data.
3. The ADO.NET objects at a glance: a DataProvider holds the Connection and Command objects and the DataAdapter (with its Select, Insert, Delete and Update commands); a DataSet holds a DataRelationCollection and a DataTableCollection, where each DataTable has data rows, data columns and data constraints. A DataReader reads from the data store through the Command, while the DataAdapter exchanges data between the data store and the DataSet.
The DataSet Class
The following table shows some important properties of the DataSet class:
| Properties | Description |
|---|---|
| CaseSensitive | Indicates whether string comparisons within the data tables are case-sensitive. |
| Container | Gets the container for the component. |
| DataSetName | Gets or sets the name of the current data set. |
| DefaultViewManager | Returns a view of data in the data set. |
| DesignMode | Indicates whether the component is currently in design mode. |
| EnforceConstraints | Indicates whether constraint rules are followed when attempting any update operation. |
| Events | Gets the list of event handlers that are attached to this component. |
| ExtendedProperties | Gets the collection of customized user information associated with the DataSet. |
| HasErrors | Indicates if there are any errors. |
| IsInitialized | Indicates whether the DataSet is initialized. |
| Locale | Gets or sets the locale information used to compare strings within the table. |
| Namespace | Gets or sets the namespace of the DataSet. |
| Prefix | Gets or sets an XML prefix that aliases the namespace of the DataSet. |
| Relations | Returns the collection of DataRelation objects. |
| Tables | Returns the collection of DataTable objects. |
The DataTable Class
The following table shows some important properties of the DataTable class:
| Properties | Description |
|---|---|
| ChildRelations | Returns the collection of child relationship. |
| Columns | Returns the Columns collection. |
| Constraints | Returns the Constraints collection. |
| DataSet | Returns the parent DataSet. |
| DefaultView | Returns a view of the table. |
| ParentRelations | Returns the ParentRelations collection. |
| PrimaryKey | Gets or sets an array of columns as the primary key for the table. |
| Rows | Returns the Rows collection. |
The DataRow Class
The DataRow object represents a row in a table. It has the following important properties:
| Properties | Description |
|---|---|
| HasErrors | Indicates if there are any errors. |
| Items | Gets or sets the data stored in a specific column. |
| ItemArray | Gets or sets all the values for the row. |
| Table | Returns the parent table. |
The DataAdapter Object
The DataAdapter object acts as a mediator between the DataSet object and the database. This helps the data set to contain data from more than one database or other data source.
The DataReader Object
The DataReader object is an alternative to the DataSet and DataAdapter combination. This object provides a connection oriented access to the data records in the database.
DbCommand and DbConnection Objects
1. The DbConnection object represents a connection to the data source. The connection could be shared among different command objects.
2. The DbCommand object represents the command or a stored procedure sent to the database for retrieving or manipulating data.
Free study material for Computer Science
Free CBSE Study Guides: Computer Science .NET Technology
Essential Notes for Computer Science
Review targeted study resources for .NET Technology tailored for learners. Utilizing these structured notes and quick-revision tools ensures complete alignment with current CBSE evaluation standards.
Verified Solutions for Computer Science
Each resource draws directly from authorized textbooks to maintain academic accuracy. Evaluating solved examples allows students to master the formal presentation and answer-writing standards expected in upcoming school exams.
Enhance Accuracy with Online Tests
For peak performance in upcoming evaluations, integrate official Computer Science sample papers directly into your study schedule. Follow up your revision by attempting online MCQ tests for .NET Technology to refine calculation speed and precision.
FAQs
The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.
Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.
Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.
in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.
All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.
Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.