Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to ASP.NET: .NET Framework, Page Structure, and Server Controls, Lecture notes of Research Methodology

t was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name stands for Active Server Pages Network Enabled Technologies. ASP.NET (software) Developer(s) Microsoft.

Typology: Lecture notes

2022/2023

Uploaded on 09/15/2023

yoga-priya-1
yoga-priya-1 🇮🇳

5 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASP.NET SUBJECT CODE : BSCS 65 &BSCA 65
UNIT I Page 1
Unit I
Introduction to ASP.NET .Net Framework (CLR, BCL, CLI) ASP.NET Basics
ASP.NET Page Structure Page Life Cycle Controls: HTML Server Controls Web Server
Controls, Web User Controls, Validation Controls, Custom Web Controls.
ASP.NET Introduction
ASP Stands for Active Server Pages, which is a powerful tool for making dynamic and
interactive web pages. An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are
executed on the server. It is a Microsoft technology, that runs on the inbuilt server provided by the
Microsoft itself i.e. IIS (Internet Information Services).
An ASP file comes with the .asp file extension. ASP.NET works on top of the HTTP protocol,
ASP.NET is a web application framework designed and developed by Microsoft. ASP.NET is
open source and a subset of the .NET Framework and successor of the classic ASP(Active Server Pages).
With version 1.0 of the .NET Framework, it was first released in January 2002.
ASP.NET is built on the CLR(Common Language Runtime) which allows the programmers to
execute its code using any .NET language(C#, VB etc.). It is specially designed to work with HTTP and
for web developers to create dynamic web pages, web applications, web sites, and web services as it
provides a good integration of HTML, CSS, and JavaScript.
.NET Framework is used to create a variety of applications and services like Console, Web, and
Windows, etc. But ASP.NET is only used to create web applications and web services. That’s why we
termed ASP.NET as a subset of the .NET Framework.
Benefits of ASP.NET?
There are a lot of reasons which makes the ASP.NET popular among the developers. Some of the
reasons are listed below:
Extending .NET Framework: ASP.NET is a subset of .NET Framework as it extends the .NET
Framework with some libraries and tools to develop web apps. The thing that it adds to the .NET
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Introduction to ASP.NET: .NET Framework, Page Structure, and Server Controls and more Lecture notes Research Methodology in PDF only on Docsity!

Unit I

Introduction to ASP.NET – .Net Framework (CLR, BCL, CLI) – ASP.NET Basics –

ASP.NET Page Structure – Page Life Cycle – Controls : HTML Server Controls – Web Server

Controls, Web User Controls, Validation Controls, Custom Web Controls.

ASP.NET Introduction

ASP Stands for Active Server Pages , which is a powerful tool for making dynamic and interactive web pages. An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are executed on the server. It is a Microsoft technology, that runs on the inbuilt server provided by the Microsoft itself i.e. IIS ( Internet Information Services ).

An ASP file comes with the .asp file extension. ASP.NET works on top of the HTTP protocol,

ASP.NET is a web application framework designed and developed by Microsoft. ASP.NET is open source and a subset of the .NET Framework and successor of the classic ASP( A ctive S erver P ages). With version 1.0 of the .NET Framework, it was first released in January 2002.

ASP.NET is built on the CLR(Common Language Runtime) which allows the programmers to execute its code using any .NET language(C#, VB etc.). It is specially designed to work with HTTP and for web developers to create dynamic web pages, web applications, web sites, and web services as it provides a good integration of HTML, CSS, and JavaScript.

.NET Framework is used to create a variety of applications and services like Console, Web, and Windows, etc. But ASP.NET is only used to create web applications and web services. That’s why we termed ASP.NET as a subset of the .NET Framework.

Benefits of ASP.NET?

There are a lot of reasons which makes the ASP.NET popular among the developers. Some of the reasons are listed below:

Extending .NET Framework: ASP.NET is a subset of .NET Framework as it extends the .NET Framework with some libraries and tools to develop web apps. The thing that it adds to the .NET

Framework is Libraries for common web patterns like MVC , Editor Extensions , the base framework to process the web requests , and web-page templating syntax like Razor , etc.

Performance: It is faster than the other web frameworks available in the market.

Backend Code: With the help of ASP.NET you can write the backend code for data access and any logic in C#.

Dynamic Pages: In ASP.NET, Razor provides the syntax for developing the dynamic web pages with the help of C# and HTML. ASP.NET can be integrated with JS(JavaScript) and it also includes the frameworks like React and Angular for the SPA(Single Page Application.)

Supporting different OS: You can develop and execute ASP.NET apps on Windows, Linux, Docker, and MacOS. The Visual Studio provides the tools to build .NET apps different OS.

ASP.NET BASICS

ASP.NET is an open-source server-side web application framework designed for web development to produce dynamic web pages developed by Microsoft to allow programmers to build dynamic web sites, applications and services.

It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to write ASP.NET code using any supported .NET language. The ASP.NET SOAP extension framework allows ASP.NET components to process SOAP messages.

ASP.NET's successor is ASP.NET Core. It is a re-implementation of ASP.NET as a modular web framework, together with other frameworks like Entity Framework. The new framework uses the new open-source .NET Compiler Platform (codename "Roslyn") and is cross platform. ASP.NET MVC, ASP.NET Web API, and ASP.NET Web Pages (a platform using only Razor pages) have merged into a unified MVC 6.

This is also called as Base Class Library and it is common for all types of applications i.e. the way you access the Library Classes and Methods in VB.NET will be the same in C#, and it is common for all other languages in .NET.

The following are different types of applications that can make use of .net class library.

  1. Windows Application.
  2. Console Application
  3. Web Application.
  4. XML Web Services.
  5. Windows Services.

In short, developers just need to import the BCL in their language code and use its predefined methods and properties to implement common and complex functions like reading and writing to file, graphic rendering, database interaction, and XML document manipulation.

3. Common Type System (CTS)

It describes set of data types that can be used in different .Net languages in common. (i.e), CTS ensures that objects written in different .Net languages can interact with each other. For Communicating between programs written in any .NET complaint language, the types have to be compatible on the basic level.

4. Common Language Specification (CLS)

It is a sub set of CTS and it specifies a set of rules that needs to be adhered or satisfied by all language compilers targeting CLR. It helps in cross language inheritance and cross language debugging.

Common language specification Rules:

It describes the minimal and complete set of features to produce code that can be hosted by CLR. It ensures that products of compilers will work properly in .NET environment.

Sample Rules:

  1. Representation of text strings
  2. Internal representation of enumerations
  3. Definition of static members and this is a subset of the CTS which all .NET languages are expected to support.
  4. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.

ASP.NET Page Structure

 ASP.NET pages are simply text files with the .aspx file name extension that can be

placed on an IIS server equipped with ASP.NET.

 When a browser requests an ASP.NET page, the ASP.NET runtime (as a component of

the .NET Framework’s Common Language Runtime, or CLR) parses and compiles the

target file into a .NET Framework class.

 The application logic now contained within the new class is used in conjunction with the

presentational HTML elements of the ASP.NET page to display dynamic content to the

user.

An ASP.NET page consists of the following elements:

 Directives  Code declaration blocks  Code render blocks  ASP.NET server controls  Server-side comments  Server-side include directives  Literal text and HTML tags

 This application logic defines variables, subroutines, functions, and more. In our page,

we place the code inside _

Code Render Blocks

Code render blocks to define inline code or inline expressions that execute when a page is rendered, and you may recognize these blocks from traditional ASP.  Code within a code render block is executed immediately as it is encountered, usually when the page is loaded or rendered for the first time, and every time the page is loaded subsequently.  Code within a code declaration block, on the other hand, occurring within script tags, is only executed when it is called or triggered by user or page interactions.  There are two types of code render blocks: inline code and inline expressions , both of which are typically written within the body of the ASP.NET page. Inline code render blocks execute one or more statements and are placed directly inside a page’s HTML within <% and %> characters.

Inline expression render blocks can be compared to Response.Write() in classic ASP. They start with <%= and end with %>, and are used to display values of the variables and methods on a page.

ASP.NET Server Controls

At the heart of ASP.NET pages lies the server controls , which represent dynamic elements that your users can interact with. There are four basic types of server control: ASP.NET controls, HTML controls, validation controls, and user controls.

All ASP.NET controls must reside within a

tag in order to function correctly. The only two exceptions to this rule are the HtmlGenericControl and the Label Web control.

Server controls offer the following advantages to ASP.NET developers:

 We can access HTML elements easily from within our code: we can change their characteristics, check their values, or even dynamically update them straight from our server-side programming language of choice.  ASP.NET controls retain their properties even after the page has been processed. This process is known as view state.  View state prevents the user from losing data that has already been entered into a form once it’s been sent to the server for processing. When the response comes back to the client’s browser, text box values, drop-down list selections, etc., are all retained through view state.

 With ASP.NET controls, developers are able to separate the presentational elements (everything the user sees) and application logic (dynamic portions of the ASP.NET page) of a page so that each can be considered separately.

Server-Side Comments

Server-side comments allow you to include, within the page, comments or notes that will not be processed by ASP.NET. Traditional HTML uses the character sequences to delimit comments; anything found within these will not be displayed to the user by the browser. ASP.NET comments look very similar, but use the sequences <%-- and --%>.

Server Side Include Directives

Server-side include directives enable developers to insert the contents of an external file anywhere within an ASP.NET page.

Alternatively, you can include a file by supplying the full virtual path. For example, if you have a subdirectory named myDirectory under the wwwroot directory, you can include a file from that directory like this:

The include directive is executed before any of the code in a page. One implication is that you cannot use variables to specify the path to the file that you want to include. For example, the following directive would generate an error:

Literal Text and HTML Tags

The final type of element that you can include in an ASP.NET page is HTML content. The static portion of your page is built with plain old HTML tags and text.

Following are the different stages of an ASP.NET page:

 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.

 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. The UICulture property of the page is also set.

 Page initialization - At this stage, the controls on the page are assigned unique ID by

setting the UniqueID property and the themes are applied. For a new request, postback

data is loaded and the control properties are restored to the view-state values.

 Page load - At this stage, control properties are set using the view state and control state

values.

 Validation - Validate method of the validation control is called and on its successful

execution, the IsValid property of the page is set to true.

 Postback event handling - If the request is a postback (old request), the related event

handler is invoked.

 Page rendering - At this stage, view state for the page and all controls are saved. The

page calls the Render method for each control and the output of rendering is written to

the OutputStream class of the Response property of page.

 Unload - The rendered page is sent to the client and page properties, such as Response

and Request, are unloaded and all cleanup done.

HTML Server Controls

HTML server controls are HTML elements that contain attributes to accessible at server side. By default, HTML elements on an ASP.NET Web page are not available to the server. These components are treated as simple text and pass through to the browser. We can convert an HTML element to server control by adding a runat="server" and an id attribute to the component.

Advantages of using HTML Server Controls:

o The HTML server controls follow the HTML centric object model. It is similar to HTML o The controls can interact with the Client side scripting o The migration of the code can be made easy by adding runat=”server attribute o The abstraction of the HTML tag is similar to the HTML server control o The controls do not possess any mechanism for identifying capabilities of the client browser

Example

<input id="UserName" type="text" size="50"runat="server" />

Controls Name Description

Button It is used to create HTML button.

Reset Button It is used to reset all HTML form elements.

Submit Button It is used to submit form data to the server.

Text Field It is used to create text input.

Text Area It is used to create a text area in the html form.

File It is used to create a input type = "file" component which is used to upload file to the server.

Password It is a password field which is used to get password from the user.

CheckBox It creates a check box that user can select or clear.

Radio Button A radio field which is used to get user choice.

Table It allows us to present information in a tabular format.

Image It displays an image on an HTML form

ListBox It displays a list of items to the user. You can set the size from two or more to specify how many items you wish to show.

Dropdown It displays a list of items to the user in a dropdown list.

Horizontal Rule It displays a horizontal line across the HTML page.

HTMLInputButton

The HTML elements allow user to create submit button, reset button and command button. The server side maps to the and .

The general syntax for the InputButton control is:

<input type=button | submit | reset id="btn1" OnServerClick="onserverclickhandler" runat="server">

When the user clicks the HTML InputButton, input from the control is processed. The response is sent back to the client.

HTMLAnchor

The HTMLAnchor is similar to the tag. It creates an hyperlink useful for navigating from one page to another.

The general syntax for the HTMLAnchor control is:

Welcome

HTMLForm

The server side control mapping the HTML element and creates a container for the web page elements.

The general syntax is:

HTMLInputText

The control is similar to HTML tag but it works on the server. It collects the information from the user.

The general form of the control is:

<input type=text | password id = "input1" maxlength = "maxnoofchar" size = "width" value = "textboxdata" runat="server" >

HTMLInputCheckBox

It works similar to the HTML checkbox control but executes on the server. The user can select values from the two option either yes or no.

The general form of the control is:

HTMLInputRadioButton

It works similar to the HTML tag. Multiple choice type questions can be created using the HTMLInputRadioButton control.

The general syntax for the control is:

HTMLSelect

User can create a listbox using the HTMLSelect control. When user needs to select an option from the list, the control is used.

The general form of the control is:

<select id="select1" runat="server" Items="optionelements" Multiple SelectedIndex="indexofcur

HTMLTable

The table is created using the

element.

The general form is:

The HtmlInputHidden Class

This class creates an HTML hidden control. You can use an HTML hidden control to hold text that the user doesn't see; this text is sent when the Web page is posted back to the server.

The HtmlInputCheckbox Class

Example Here, we are implementing an HTML server control in the form. // htmlcontrolsexample.aspx

  1. < %@ Page Language="C#" AutoEventWireup="true" CodeBehind="htmlcontrolsexample.aspx.cs"
  2. Inherits="asp.netexample.htmlcontrolsexample" % >
  3. 3. ** 4. **** 5. **** 6. **** 7. **** 8. **** 9. **** 10. **
    ** 11. **** 12. **** 13. **
    ** 14. **** 15. **** 16. ****

This application contains a code behind file. // htmlcontrolsexample.aspx.cs

  1. using System;
  2. namespace asp.netexample
  3. {
  4. public partial class htmlcontrolsexample : System.Web.UI.Page
  5. {
  6. protected void Page_Load( object sender, EventArgs e)
  7. {
  8. }
  9. protected void Button1_Click( object sender, EventArgs e)
  10. {
  11. string a = Request.Form["Text1"];
  12. Response.Write(a);
  13. }
  14. }

Output : When we click the button after entering text, it responses back to client.

Web Server Controls Web server controls provide a higher level of abstraction than HTML server controls because their object model matches closely with the .NET Framework, rather than matching with the requirements of HTML syntax. In the HTML source for your page, Web server controls are represented as XML tags rather than as HTML elements. But remember, the browser receives standard HTML in any case.

Web server controls have a number of advanced features:

 Web server controls provide a rich object model that closely matches with the rest of the .NET Framework.

 Web server controls have built-in automatic browser detection capabilities. They can render their output HTML correctly for both uplevel and downlevel browsers.

Enabled Indicates whether the Web server control is allowed to receive the focus.

EnableViewState Indicates whether view state is enabled for the Web server control.

Font Specifies a FontInfo object that represents the font properties of a Web server control.

ForeColor Specifies the color of text in the Web server control.

Height Specifies the height of the Web server control.

ID Specifies an identifier for the Web server control.

Parent Represents the parent control of the Web server control.

Style Specifies the collection of CSS properties applied to the Web server control.

TabIndex Specifies the tab order of a Web server control.

ToolTip Specifies the pop-up text displayed by the Web server control when the mouse hovers over it.

Visible Indicates whether the Web server control is visible.

Width Specifies the width of the Web server control.

Common Web Server Controls

The following sections discuss some simple but commonly used controls. These controls have a small number of properties, and they are usually rendered as a single HTML element.

The Label Control

A Label control is used to display read-only information to the user. It is generally used to label other controls and to provide the user with any useful messages or statistics. It exposes its text content through the Text property. This property can be used to manipulate its text programmatically

The TextBox Control

A TextBox control provides an area that the user can use to input text. Thus, this server control can be rendered as three different types of HTML elements— , , and