Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
154 views9 pages

MCA 401 (Unit 04)

The document provides an introduction to ASP.NET and web applications using C#. It discusses static and dynamic web pages, how HTTP requests work, benefits of web applications, components of websites like pages and browsers, an overview of classic ASP and differences from ASP.NET, the ASP.NET page lifecycle, server controls for rendering HTML, and introduction to web forms controls in ASP.NET.

Uploaded by

Priyal Agarwal
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)
154 views9 pages

MCA 401 (Unit 04)

The document provides an introduction to ASP.NET and web applications using C#. It discusses static and dynamic web pages, how HTTP requests work, benefits of web applications, components of websites like pages and browsers, an overview of classic ASP and differences from ASP.NET, the ASP.NET page lifecycle, server controls for rendering HTML, and introduction to web forms controls in ASP.NET.

Uploaded by

Priyal Agarwal
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/ 9

UNIT 04 (.

NET Framework using C#)


Introduction to ASP.NET with C#
(1) Introduction of Web Application:
 The term web application refers to a software system that provides a user interface through a web
browser. Examples of web applications include blogs, online shopping, search engines, etc.
 Web applications can be simple consisting of only static web pages or they can be dynamic and
interactive.
 Static web pages are stored in the file system of web server usually displays the same information to all
visitors, whereas dynamic pages are constructed by a program that produce the HTML.
How the (static) web work?
We know that, to open a web page we enter URL and web browser displays web page that we request. Let's
discuss the steps that happen behind the scene.
a. The user enters a URL in the browser.
b. The browser sends a request to the web server over the internet.
c. Web Server examines the request and based on the request server finds the requested page already stored
in its local drive.
d. Web Server sends the response to the web client (browser).
e. Browser gets the HTML and renders it into a display for the user.

The request and response communications over the internet between client and server are held using the HTTP
protocol. That's why the server is often called as HTTP server. When a server answers a request, the server
usually sends some type of content to the browser so that the browser can display it. Servers often send the
browser a set of instructions written in HTML. HTTP uses URLs (Uniform Resource Locator) to identify
data on the Internet.
Benefits of a web application:
a. Web applications run on multiple platforms regardless of OS or device as long as the browser is
compatible
b. All users access the same version, eliminating any compatibility issues.
c. They are not installed on the hard drive, thus eliminating space limitations
d. They reduce costs for both the business and end user as there is less support and maintenance required
by the business and lower requirements for the end user’s computer.

Kushal Johari, Faculty of Computer Applications Page 1


(2) Web Site:
 Website: A website is a group of web pages that have information in the various pages that contain
similar subject materials. For instance, the web site would have a name (subject) such as
www.invertisuniversity.ac.in and have several pages related to academics. The website has a main web
page commonly called the Homepage (index.html or default.html). The site's address will display the
homepage and you can click on hyperlinks to go to other pages on the website.

 Webpage: A webpage is a text page written in a form of HTML (hyper text markup language) that
contains text, links or tags that will display graphics, audio, video, downloadable files and of course
other web pages. A web page is a page containing information on a subject.

 Web browser: A web browser (Microsoft's Internet explorer or Google Chrome for example) is a
program that translates the code that makes up a webpage (HTML) into a form that we can recognize.

 Hyper links: A hyper link is usually shown as a blue underlined term on a web page that equates to
another web page on the same website or another related website.

 Web server: A web server is the actual computer that is set up to serve web pages to the world through
the internet. This takes a very fast internet connection because of the possibility of hundreds of people
using the server and posted web sites at any given time.

(3) A Review of Classic ASP:


What is ASP?
 ASP stands for Active Server Pages
 ASP is a Microsoft Technology
 ASP is a type of server-side technology that runs inside a web server
 It’s a tool for building web applications and interactive websites.
 The first version of ASP (now called “Classic ASP”) was introduced by Microsoft in 1998 by Microsoft
as its first server side scripting language.
What is an ASP File?
 An ASP file has the file extension “.asp” and is normally written in VBScript.
 An ASP file is just the same as an HTML file
 An ASP file can contain server scripts in addition to HTML
 Server scripts in an ASP file are executed on the server
What can ASP do?
 Edit, change, add content, or customize any web page
 Respond to user queries or data submitted from HTML forms
 Access databases or other server data and return results to a browser
Difference between ASP and ASP.NET:

SNo ASP ASP.NET


1 ASP is the interpreted languages. ASP.NET is the compiled language.
ASP uses ADO (ActiveX Data Objects) ASP.NET uses ADO.NET to connect and work
2
technology to connect and work with databases. with database.
3 ASP is partially object oriented. ASP.NET is fully object oriented.
4 ASP Pages have the file extension .asp ASP.NET Pages have the file extension .aspx
5 ASP doesn’t have the concept of inheritance ASP.NET inherit the class written in code behind

Kushal Johari, Faculty of Computer Applications Page 2


6 Error handling is very poor in ASP. Error handling is very good in ASP.NET.
ASP has maximum four in-built classes i.e.
7 ASP.NET has more than 2000 in-built classes.
Request, Response, Session and Application.

(4) ASP.NET Web Applications (ASP.NET Page Life Cycle):


ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build
dynamic web sites. It allows you to use a full featured programming language such as C# or VB.NET to build
web applications easily.
ASP.NET Page Life Cycle: Following are the different stages of an ASP.NET page:
1. Page request - When ASP.NET gets a page request, it decides whether to parse and compile the page,
or there would be a cached version of the page; accordingly the response is sent.
2. Starting of page life cycle - At this stage, the Request and Response objects are set. If the request is an
old request or post back, the IsPostBack property of the page is set to true.
3. Page initialization - At this stage, the controls on the page are assigned unique ID by setting the
UniqueID property and the themes are applied.
4. Page load - At this stage, control properties are set using the view state and control state values.
5. Validation - Validate method of the validation control is called and on its successful execution, the
IsValid property of the page is set to true.
6. Postback event handling - If the request is a postback (old request), the related event handler is
invoked.
7. Page rendering - At this stage, view state for the page and all controls are saved. The page calls the
Render method (It is a method called to generate the output to send to the client.) for each control and
the output of rendering is written to the OutputStream class of the Response property of page.
8. Unload - The rendered page is sent to the client and page properties, such as Response and Request, are
unloaded and all cleanup done.

(5) Rendering HTML with Server Controls:


Controls are small building blocks of the graphical user interface, which include text boxes, buttons, check
boxes, list boxes, labels, and numerous other tools. Using these tools, the users can enter data, make selections
and indicate their preferences.
ASP.NET server controls are the primary controls used in ASP.NET. These controls can be grouped into the
following categories:
1. Validation controls - These are used to validate user input and they work by running client-side script.
2. Data source controls - These controls provides data binding to different data sources.
3. Data view controls - These are various lists and tables, which can bind to data from data sources for
displaying.
4. Personalization controls - These are used for personalization of a page according to the user
preferences, based on user information.
5. Login and security controls - These controls provide user authentication.
6. Master pages - These controls provide consistent layout and interface throughout the application.

Kushal Johari, Faculty of Computer Applications Page 3


7. Navigation controls - These controls help in navigation. For example, menus, tree view etc.
8. Rich controls - These controls implement special features. For example, AdRotator, FileUpload, and
Calendar control.
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
Although ASP.NET server controls can perform every job accomplished by the HTML server controls, the later
controls are useful in the following case:
 Converting a HTML page to run under ASP.NET

Working with Web Forms Controls and C#


(6) Introduction to Web Forms Controls:
ASP.NET provides various controls like: Server Controls and HTML Controls for the Web Forms.

Server Controls:
The following table contains the server-side controls for the Web Forms.

Sno Control Name Applicable Events Description


1 Label None It is used to display text on the HTML page.
2 TextBox TextChanged It is used to create a text input in the form.
3 Button Click, Command It is used to create a button.
It is used to create a button that looks similar to the
4 LinkButton Click, Command
hyperlink.
It is used to create an imagesButton. Here, an image works
5 ImageButton Click
as a Button.
It is used to create a hyperlink control that responds to a
6 Hyperlink None
click event.
7 DropDownList SelectedIndexChanged It is used to create a dropdown list control.
It is used to create a ListBox control like the HTML
8 ListBox SelectedIndexCnhaged
control.
9 CheckBox CheckChanged It is used to create checkbox.
It is used to create a group of check boxes that all work
10 CheckBoxList SelectedIndexChanged
together.
11 RadioButton CheckChanged It is used to create radio button.
It is used to create a group of radio button controls that all
12 RadioButtonList SelectedIndexChanged
work together.
13 Image None It is used to show image within the page.

14 Panel None It is used to create a panel that works as a container.

Kushal Johari, Faculty of Computer Applications Page 4


15 PlaceHolder None It is used to set placeholder for the control.
SelectionChanged, It is used to create a calendar. We can set the default date,
16 Calendar
VisibleMonthChanged move forward and backward etc.
17 Table None It is used to create table.

HTML Controls:
These controls render by the browser. We can also make HTML controls as server control.

Sno Controls Name Description


1 Button It is used to create HTML button.
2 Reset Button Resets all other HTML form elements on a form to a default value
Automatically POSTs the form data to the specified page listed in the Action
3 Submit Button
attribute in the FORM tag
4 Text Field Gives the user an input area on an HTML form
5 Text Area Used for multi-line input on an HTML form
Places a text field and a Browse button on a form and allows the user to select a file
6 File Field
name from their local machine when the Browse button is clicked
An input area on an HTML form, although any characters typed into this field are
7 Password Field
displayed as asterisks
8 CheckBox Gives the user a check box that they can select or clear
9 Radio Button Used two or more to a form, and allows the user to choose one of the controls
10 Table Allows you to present information in a tabular format
11 Image Displays an image on an HTML form
Displays a list of items to the user. You can set the size from two or more to specify
12 ListBox how many items you wish show. If there are more items than will fit within this
limit, a scroll bar is automatically added to this control.
Displays a list of items to the user, but only one item at a time will appear. The user
13 Dropdown can click a down arrow from the side of this control and a list of items will be
displayed.

(7) Overview of ASP.NET Validation Controls:


ASP.NET provides the following validation controls:
1. RequiredFieldValidator
2. RangeValidator
3. CompareValidator
4. RegularExpressionValidator

RequiredFieldValidator:
The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box
to force input into the text box.

RangeValidator:
The RangeValidator control verifies that the input value falls within a predetermined range.

CompareValidator:
The CompareValidator control compares a value in one control with a fixed value or a value in another control.

Kushal Johari, Faculty of Computer Applications Page 5


RegularExpressionValidator:
The RegularExpressionValidator allows validating the input text by matching against a pattern of a regular
expression. The regular expression is set in the ValidationExpression property.
The following table summarizes the commonly used syntax constructs for regular expressions:

Sno Character Escapes Description


1 \b Matches a backspace.
2 \t Matches a tab.
3 \v Matches a vertical tab.
4 \n Matches a new line.
5 \ Escape character.

(8) Client-Side and Server Side Validation:


Why do we need validation?
Validation is the main threshold to process the data. We store the textbox value into a database table. Before
moving to storing the data into the database, first, we check the value of each textbox.
In web technology, there are two types of validation.
1. Client Side
2. Server Side
Client Side:
Before validating data in the server, first, we validate it on the client side. User input that is validated in the
browser before submitting to the server is called Client-side validation.
Server Side:
This validation is executed after client-side validation if we have it. But we should or must have server-side
validation.

(9) File Upload Controls:


ASP.NET has two controls that allow users to upload files to the web server. Once the server receives the
posted file data, the application can save it, check it, or ignore it. The following controls allow the file
uploading:
1. HtmlInputFile : an HTML server control
2. FileUpload : an ASP.NET web control

Both controls allow file uploading, but the FileUpload control automatically sets the encoding of the form,
whereas the HtmlInputFile does not do so.
Once, the user has entered the filename in the text box by typing the name or browsing, the SaveAs method of
the FileUpload control can be called to save the file to the disk.
The basic syntax of FileUpload is:
<asp:FileUpload ID= "Uploader" runat = "server" />

The FileUpload class has the following read-only properties:

Sno Properties Description


1 FileBytes Returns an array of the bytes in a file to be uploaded.
2 FileContent Returns the stream object pointing to the file to be uploaded.

Kushal Johari, Faculty of Computer Applications Page 6


3 FileName Returns the name of the file to be uploaded.
4 HasFile Specifies whether the control has a file to upload.
5 PostedFile Returns a reference to the uploaded file.

(10) Master Page:


A master page provides the layout and functionality to other pages.
i. It is an ASP.NET file with the .master extension with a predefined layout that can include static text,
HTML elements and server controls.
ii. A Master page offers a template for one or more web forms.
iii. When users request the content page, ASP.NET merges the layout of the master page with the content of
the content page and produce output.
iv. Master pages allow you to create a consistent layout for the pages in your application.
v. It defines the look, feel and standard behavior that you want for all of the pages in your application.
vi. It provides a template for other pages, with shared layout and functionality.
vii. It contains markup and controls that should be across multiple pages in your site.

(11) Ad Rotator Control:


AdRotator is a control in ASP.NET that is all about ads in Web pages. It displays a number of ad images and
rotates them or loads them when a page is refreshed. The ASP.NET AdRotator control uses an XML file to
store the ads and their information.
The AdRotator control randomly selects banner graphics from a list, which is specified in an external XML
schedule file. This external XML schedule file is called the advertisement file.
The AdRotator control allows you to specify the advertisement file and the type of window that the link should
follow in the AdvertisementFile and the Target property respectively.
The basic syntax of adding an AdRotator is as follows:
<asp:AdRotator runat = "server" AdvertisementFile = "adfile.xml" Target = "_blank" />

The Advertisement File:


The advertisement file is an XML file, which contains the information about the advertisements to be displayed.

Properties and Events of the AdRotator Class:


The AdRotator class is derived from the WebControl class and inherits its properties. Apart from those, the
AdRotator class has the following properties:

Sno Properties Description


1 AdvertisementFile The path to the advertisement file.
The element name of the field where alternate text is provided. The default
2 AlternateTextFeild
value is AlternateText.
The name of the specific list of data to be bound when advertisement file is not
3 DataMember
used.
4 DataSource Control from where it would retrieve data.
5 DataSourceID Id of the control from where it would retrieve data.

6 Font Specifies the font properties associated with the advertisement banner control.

Kushal Johari, Faculty of Computer Applications Page 7


The element name of the field where the URL for the image is provided. The
7 ImageUrlField
default value is ImageUrl.
8 KeywordFilter For displaying the keyword based ads only.

The element name of the field where the URL to navigate to is provided. The
9 NavigateUrlField
default value is NavigateUrl.

10 Target The browser window or frame that displays the content of the page linked.

11 UniqueID Obtains the unique, hierarchically qualified identifier for the AdRotator control.

(12) Login Controls:


The login control provides a user interface for managing the authentication of users in a website. The
authentication is performed on the basis of username and password. The page acess can be restricted by the use
of the login controls.

The Login class contains various methods, properties, and events to work with. Some of them are as listed
below:
i. CreateChildControls: It creates an individual control of the Login control and the event handlers are
associated with it.
ii. OnLoggingIn: It raises the LoggingIn event when the user adds the login data before the authentication
is completed.
iii. OnLoggedIn: It raises an LoggedIn event when the user log into the web site after the authentication is
completed
iv. OnAuthenticate: It raises an Authenticate event for the user authentication.

Properties of the Login Control:


i. CreateUserIconUrl: It retrieves the location of the image to display the link to the user.
ii. CreateUserUrl: It specifies or retrieves the URL for the new user page.
iii. DisplayRememberMe: It specifies the value stating whether to display the RememberMe checkbox.
iv. FailureText: It displays the text when the login attempt fails
v. HelpPageText: It specifies the text of link to the login help page.
vi. Password: It retrieves the password entered by the user

Events of the Login Control:


i. LoggedIn: It is initiated when the user logs in the web site and is authenticated.
ii. LoggingIn: It is initiated when the user submits the login information.
iii. LoginError: It is initiated when a login error is detected.

The Login control at the design time is as shown below:

Kushal Johari, Faculty of Computer Applications Page 8


(13) Session and Cookies:
Sessions:
Sessions are stored per-user in memory (or an alternative Session-State) on the server. Sessions use a cookie
(session key) to tie the user to the session. This means no "sensitive" data is stored in the cookie on the user’s
machine.
Sessions are generally used to maintain state when you navigate through a website. However, they can also be
used to hold commonly accessed objects.

i. Session can store any type of data because the value is of data type of “object”
ii. These are stored at server side.
iii. Sessions are secured because it is stored in binary format/encrypted form and gets decrypted at server.
iv. Session is independent for every client i.e. individual for every client.
v. There is no limitation on the size or number of sessions to be used in an application.
vi. We cannot disable the sessions. Sessions can be used without cookies also.
vii. The disadvantage of session is that it is a burden or an overhead on server.
viii. Sessions are called as Non-Persistent cookies because its life time can be set manually

Cookies:
Cookies are stored per-user on the user’s machine. A cookie is usually just a bit of information. No sensitive
information should ever be stored in a cookie.

i. Cookies can store only “string” data type.


ii. They are stored at client side.
iii. Cookie is non-secure since stored in text-format at client side.
iv. Cookies may or may not be individual for every client.
v. Size of cookie is limited to 40 and number of cookies to be used is restricted to 20.
vi. Cookies can be disabled.
vii. Since the value is in string format there is no security.

Kushal Johari, Faculty of Computer Applications Page 9

You might also like