Saturday, February 6, 2016

ASP .Net Basic Concept

Feel Free to share the Information
WhatsUp: 09731764134

Any one who want to develop a web application must have the following systems:

1. A web server.
2. An editor to develop the web pages.
3. A browser to view the web page you develop.
4. A database program like MS Access, SQL Server etc, if your web site need to save data into a database.

In the real world situation, a web server will be hosted on a secure server, located in a safe place and will be always connected to high speed internet. However, to develop a web application, you don't need to worry about security and internet connectivity. You can use your own development computer as the 'Web Server'.

Web Server:-

There are several types of web servers. But if you like to develop ASP.NET web applications, you need a specific web server called 'Internet Information Server' (IIS).

IIS comes as part of Windows. But it is not installed by default, when you install Windows.

Editor to develop web pages:-

Ideally, you do not need any special editor to develop a web application. If you are an expert, you can simply use notepad to type HTML and the code for the web pages. However, who want to hand-wash the vessels when there is a dish washer ?

You don't need to make your hands dirty! Microsoft gives a tool called 'Visual Studio .
NET' to edit web pages and write code for ASP.NET.

Visual Studio .NET (VS.NET)

Visual Studio .NET allows to easily create web pages. Some of the benefits in using Visual Studio .NEt are:
·       You can simply drag and drop html controls to the web page and VS.NET will automatically write the HTML tags for you.
·       Start typing an HTML tag and VS.NET will complete it! When you start typing a tag, VS.NET will show you the HTML tags starting with the characters you typed. So, you don't need to even remember all the tags.
·       If you type any HTML tags wrong, VS.NET will highlight the errors and tell you how to correct it.
So, even if you are not an expert, VS.NET can help you develop great web pages.


You need a browser to view the web pages you create. If you have any windows operating system in your computer, you will already have a free browser (called 'Internet Explorer')

Database program:

A database program like MS Access or SQL Server is required only if you need to save data into database. It is not mandatory that all web sites need a database program.
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. ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web 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 the name of the Microsoft technology used for web site development.
·       ASP.NET is NOT a programming language like C# or VB.NET
·       ASP.NET development requires a programming language like C# or VB.NET to write code.
·       There are several other technologies exist for web development (Eg: PHP ). ASP.NET is the technology from Microsoft and it is the widely used one.
·       ASP.NET technology comes with a rich set of components and controls that make the web development very easy.
·       Visual Studio .NET is the editor from Microsoft which helps you develop ASP.NET web sites faster and easily.
·       IIS is the web server from Microsoft which supports ASP.NET. To develop ASP.NET web sites, you must have IIS installed in your computer
·       ASP stands for Active Server Pages
·       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
·       PHP is a server-side HTML embedded scripting language. It provides web developers with a full suite of tools for building dynamic websites

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 request comes into Microsoft's IIS Web server its extension is examined and, based on this extension, the request is either handled directly by IIS or routed to an ISAPI extension. An ISAPI extension is a compiled class that is installed on the Web server and whose responsibility it is to return the markup for the requested file type.

By default, IIS handles the request, and simply returns the contents of the file requested. This makes sense for static files, like images, HTML pages, CSS files, external JavaScript files, and so on. For example, when a request is made for a .html file, IIS simply returns the contents of the requested HTML file.
For files whose content is dynamically generated, the ISAPI extension configured for the file extension is responsible for generating the content for the requested file. For example, a Web site that serves up classic ASP pages has the .asp extension mapped to the asp.dll ISAPI extension. The asp.dll ISAPI extension executes the requested ASP page and returns its generated HTML markup. If your Web site serves up ASP.NET Web pages, IIS has mapped the .aspx to aspnet_isapi.dll, an ISAPI extension that starts off the process of generating the rendered HTML for the requested ASP.NET Web page.

In Shortly :
·       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

Advantages Using ASP.NET :

Ø       ASP.NET drastically reduces the amount of code required to build large applications
Ø       ASP.NET makes development simpler and easier to maintain with an event-driven, server-side programming model
Ø       ASP.NET pages are easy to write and maintain because the source code and HTML are together
Ø       The source code is executed on the server. The pages have lots of power and flexibility by this approach
Ø       The source code is compiled the first time the page is requested. Execution is fast as the Web Server compiles the page the first time it is requested. The server saves the compiled version of the page for use next time the page is requested
Ø       The HTML produced by the ASP.NET page is sent back to the browser. The application source code you write is not sent and is not easily stolen
Ø       ASP.NET makes for easy deployment. There is no need to register components because the configuration information is built-in
Ø       The Web server continuously monitors the pages, components and applications running on it. If it noticies memory leaks, infinite loops, other illegal software or activities, it seamlessly kills those activities and restarts itself
Ø       ASP.NET validates information (validation controls) entered by the user without writing a single line of code
Ø       ASP.NET easily works with ADO .NET using data-binding and page formatting features
Ø       ASP.NET applications run faster and counters large volumes of users without performance problems

Asp.Net Life Cycle:

Ø     Page_Init
The server controls are loaded and initialized from the Web form's view state. This is the first step in a Web form's life cycle.
Ø     Page_Load
The server controls are loaded in the page object. View state information is available at this point, so this is where you put code to change control settings or display text on the page.
Ø     Page_PreRender
The application is about to render the page object.

Ø     Page_Unload
The page is unloaded from memory.

Ø     Page_Disposed
The page object is released from memory. This is the last event in the life of a page object.
Ø     Page_Error
An unhandled exception occurs.

Ø     Page_AbortTransaction
A transaction is aborted.

Ø     Page_CommitTransaction
A transaction is accepted.

Ø     Page_DataBinding
A server control on the page binds to a data source.

Ø     Process Request Method finally renders HTML Page

View state :
View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings. This information is then put into the view state hidden field or fields.
The web is stateless. But in ASP.NET, the state of a page is maintained in the page itself automatically. The values are encrypted and saved in hidden controls. this is done automatically by the ASP.NET. Standard Controls:
Label :
The Label control displays text in a set location on the page. Unlike static text, the Text property of a label can be set programmatically.


The TextBox control enables the user to enter text. By default, the TextMode of TextBox is SingleLine, but you can modify the behavior of TextBox by setting the TextMode to Password or MultiLine.

The display width of TextBox is determined by its Columns property. If TextMode is MutliLine, the display height of TextBox is determined by the Rows property.


The Button control provides a command button-style control that is used to post a Web Forms page back to the server.
Like the Button control, LinkButton is used to post a Web Forms page back to the server.
Like the Button control, ImageButton is also used to post back to the server.


The HyperLink control is used to navigate from the client to another page.

The DropDownList control provides a single-select drop-down list.
Note : The DropDownList includes DataTextField and DataValueField properties for specifying the field value to render for the Text and Value properties of its list items, respectively. The value of the currently selected item is exposed through the SelectedValue property of DropDownList.

The ListBox control provides a single-selection or multiple-selection list. To enable multiple selection, set the SelectionMode property to Multiple.
The RadioButton control permits you to intersperse the radio buttons in a group with other content in the page. The buttons are grouped logically because they all share the same GroupName.

The RadioButtonList control provides a single-selection checked list. Like other list controls, RadioButtonList has an Items collection with members that correspond to each item in the list. To determine which items are selected, test the Selected property of each item.

You can control the rendering of the list with the RepeatLayout and RepeatDirection properties. If the value of RepeatLayout is Table, the list will be rendered in a table. If it is set to Flow, the list will be rendered without any table structure. By default, the value of RepeatDirection is Vertical. Setting this property to Horizontal causes the list to be rendered horizontally.

The CheckBoxList control provides a multiple-selection checked list. Like other list controls, CheckBoxList has an Items collection with members that correspond to each item in the list. To determine which items are selected, test the Selected property of each item.

You can control the rendering of the list with the RepeatLayout and RepeatDirection properties. If RepeatLayout is Table, the list is rendered within a table. If it is set to Flow, the list is rendered without any table structure. By default, RepeatDirection is Vertical. Setting this property to Horizontal causes the list to be rendered horizontally.

The Image control displays the image defined by its ImageUrl property.

Use the ImageMap control to create an image that contains defined hotspot regions. When a user clicks a hot spot region, the control can either generate a post back to the server or navigate to a specified URL. For example, you can use this control to display a map of a geographical region. When a user clicks a specific region on the map, the control navigates to a URL that provides additional data about the selected region. You can also use this control to generate a post back to the server and run specific code based on the hot spot region that was clicked. For example, you can use an ImageMap control to capture user responses such as votes. When a user clicks the hot spot region defined for yes votes, code is called to record a yes response in a database. When a user clicks on the hot spot region defined for no votes, a no response is recorded. You can also mix these two scenarios within a single ImageMap control. For example, you can specify one hot spot region to navigate to a URL and another hot spot region to post back to the server.

The BulletedList control is used to create a list of items formatted with bullets. To specify the individual list items that you want to appear in a BulletedList control, place a ListItem object for each entry between the opening and closing tags of the BulletedList control.

List with circle bullet style
To display a set of items as a list and decorate it with bullets. Uses the BulletedList control provided by ASP.NET and set the BulletedList.BulletSyle property to decorate the list.

List of hyperlinks
A developer needs to add a list of links to his/her page; he/she finds that if he/she creates a HyperLink control per link this will be time intensive and hard to maintain. Instead, he/she takes advantage of the BulletedList and sets the BulletedListDisplayMode property to BulletedListDisplayMode.HyperLink. He/she defines the Url for navigation by setting the value property of the ListItem. In addition, since he/she is using the BulletedList control, he/she improves the presentation of it by defining the BulletStyle or the BullletImageUrl.

This control enables a developer to store a non-displayed value.
The HiddenField control is used to store a value that needs to be persisted across posts to the server. It is rendered as an element.

A Literal control is used to display text. The developer cannot apply a style to a literal control.

Encoding Content in the Literal Control :
The Literal control supports the Mode property, which specifies how the control handles markup that you add to it. You can set the Mode property to these values:

Transform. Any markup you add to the control is transformed to accommodate the protocol of the requesting browser. This setting is useful if you are rendering content to mobile devices that use protocol other than HTML.

PassThrough. Any markup you add to the control is rendered as-is to the browser.

Encode. Any markup you add to the control is encoded using the HtmlEncode method, which converts HTML encoding into its text representation. For example, a <b> tag is rendered as &lt;b&gt;. Encoding is useful when you want the browser to display markup rather than interpret it. Encoding is also useful for security, to help prevent malicious markup from being executed in the browser, and is recommended if you are displaying strings from an untrusted source.
The Calendar control displays a month calendar from which users can select dates.
Date Selection Modes
Calendar supports four date selection modes, as described in the following table.

Mode Description
Day User can select any single day.
DayWeek User can select a single day, or an entire week.
DayWeekMonth User can select a single day, an entire week, or the entire visible month.
None Date selection is disabled.

Selection Link Graphics
The Calendar control can use either text or graphics for its selection links.
Selection Link Text
The Calendar control can also use text labels for week or month selection, as shown in the following example.

Mode Description
Day User can select any single day.
DayWeek User can select a single day, or an entire week.
DayWeekMonth User can select a single day, an entire week, or the entire visible month.
None Date selection is disabled.

Selection Link Graphics
The Calendar control can use either text or graphics for its selection links.
Selection Link Text
The Calendar control can also use text labels for week or month selection, as shown in the following example.

The AdRotator control presents ad images that, when clicked, navigate to a new Web location. Each time the page is loaded into the browser, an ad is randomly selected from a predefined list.

The rotation schedule for ads is defined in an XML file. The following example demonstrates a rotation schedule in the file ads.xml.

The rotation file defines the following attributes of each ad. Except for ImageUrl, these attributes are optional.
Attribute Description
ImageUrl :- An absolute or relative URL to the ad image file.
NavigateUrl:- The Web location to navigate to when the image is clicked. If NavigateUrl is not set, the image is not clickable.
AlternateText:- The text to render as the ALT attribute of the image. When the page is viewed with Microsoft Internet Explorer, this acts as a ToolTip for the ad.
Keyword Specifies a category for the ad that the page can filter on.
Impressions A number that indicates the "weight" of the ad in the schedule of rotation relative to the other ads in the file. The larger the number, the more often the ad will be displayed.

The FileUpLoad control enables you to upload file to the server. It displays a text box control and a browse button that allow users to select a file to upload to the server.

-->The user specifies the file to upload by entering the fully qualified path to the file on the local computer (for example, "C:\MyFiles\TestFile.txt") in the text box of the control. Alternately, the user can select the file by clicking the Browse button and then locating it in the Choose File dialog box.
-->The FileUpload control does not automatically save a file to the server after the user selects the file to upload. You must explicitly provide a control or mechanism to allow the user to submit the specified file.
For example, you can provide a button that the user clicks to upload the file. The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server.
Typically, the SaveAs method is called in an event-handling method for an event that raises a post back to the server.
For example, if you provide a button to submit a file, you could place the code to save the file inside the event-handling method for the button's click event.

The Wizard control provides navigation through a series of steps that collect information incrementally from a user. Many websites include functionality that collects information from the end user (e.g. checking out on an ecommerce website).

The Wizard consists of:
Collection of WizardSteps: Each WizardStep contains a discrete piece of content to be displayed to the user. Only one WizardStep will be displayed at a time.
Navigation Buttons: The navigation area below each WizardStep that contains the navigation buttons to go the next and pervious steps in the wizard.
SideBar: An optional element that contains a list of all WizardSteps and provides a means to skip around the WizardSteps in a random order.
Header: An optional element to provide consistent information at the top of the WizardStep.
The StepType associated with each WizardStep determines the type of navigation buttons that will be displayed for that step.

The Step Types are:
Start: Displays a Next button.
Step: Displays Next and Previous buttons.
Finish: Displays a Finish button.
Complete: Displays no navigation buttons and hides the SideBar if it is displayed.
Auto:One of the step types listed above is selected based on the order of the step in the collection (e.g. the first step will have a Next button).
Note: If you are using the WizardControl in a visual designer you can switch to view different WizardSteps on the design surface. To improve the development experience, when you run the page whatever WizardStep was displayed in the designer will be the step you start on. This makes it easier to debug new steps you might be adding to a complicated wizard where each WizardStep requires a lot of validated input. However, you MUST REMEMBER to change the WizardStep back to the first step when you are done making changes.

The Xml control can be used to write out an XML document or the results of an XSL Transform. The DocumentSource specifies the XML document to use. This document will be written directly to the output stream unless TransformSource is also specified. TransformSource must be a valid XSL Transform document and will be used to transform the XML document before its contents are written to the output stream.

MultiView and View:
The MultiView control represents a control that acts as a container for groups of View controls. It allows you to define a group of View controls, where each View control contains child controls.

The Panel control is a container for other controls. It is especially useful when you want to generate controls programmatically, hide/show a group of controls, or localize a group of controls.
The Direction property is useful for localizing a Panel control's content to display text for languages that are written from right to left, such as Arabic or Hebrew.
The Panel control provides several properties that allow you to customize the behavior and display of its contents. Use the BackImageUrl property to display a custom image for the Panel control. Use the ScrollBars property to specify scroll bars for the control.

The PlaceHolder control can be used as a container control within a document to dynamically load other controls. The PlaceHolder control has no HTML-based output and is used only to mark a spot for other controls that can be added to the Controls collection of the PlaceHolder during page execution.

Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use this Control to add or remove a control in the PlaceHolder control.
Note: The PlaceHolder control does not produce any visible output (it only acts as a container for other controls on the Web page).

 What is Postback?
Postback is an event that is triggered when a action is performed by a control on a page. for eg. when you click on a button the data on the page is posted back to the server for processing.
   Each Asp .net page when loaded goes through a regular creation and destruction cycle like Initialization, Page load etc., in the beginning and unload while closing it. This Postback is a read only property with each Asp .Net Page (System.Web.UI.Page) class. This is false when the first time the page is loaded and is true when the page is submitted and processed. This enables users to write the code depending on if the PostBack is true or false (with the use of the function Page.IsPostBack()).
IsPostback is normally used on page _load event to detect if the page is getting generated due to postback requested by a control on the page or if the page is getting loaded for the first time.

What is a web server?

A Web server is a software program which serves web pages to web users (browsers).

A web server delivers requested web pages to users who enter the URL in a web browser. Every computer on the Internet that contains a web site must have a web server program.

The computer in which a web server program runs is also usually called a "web server". So, the term "web server" is used to represent both the server program and the computer in which the server program runs.

Characteristics of web servers

A web server computer is just like any other computer. The basic characteristics of web servers are:

- It is always connected to the internet so that clients can access the web pages hosted by the web server.
- It has an application called 'web server' running always.

In short, a 'web server' is a computer which is connected to the internet/intranet and has a software called 'web server'. The web server program will be always running in the computer. When any user try to access a website hosted by the web server, it is actually the web server program which delivers the web page which client asks for. All web sites in the Internet are hosted in some web servers sitting in different parts of the world.
Web Server is a hardware or a software ?
From the above definition, you must have landed up in confusion “Web server is a hardware or a software”

Mostly, Web server refers to the software program, which serves the clients request. But as we mentioned earlier in this chapter, the computer in which the web server program is also called 'web server".

Web Server – Behind the Scene
Have you ever had a thought how the page is made available to the browser?

Your answer would be, “I typed in the URL and clicked on some link, I dropped into this page.”

But what happed behind the scenes to bring you to this page and make you read this line of text.

So now, lets see what is actually happening behind the scene. The first you did is, you typed the URL in the address bar of your browser and pressed your return key.

We could break this URL into two parts,
1.    The protocol we are going to use to connect to the server (http)
2.    The server name (
The browser breaks up the URL into these parts and then it tries to communicate with the server looking up for the server name. Actually, server is identified through an IP address but the alias for the IP address is maintained in the DNS Server or the Naming server. The browser looks up these naming servers, identifies the IP address of the server requested and gets the site and gets the HTML tags for the web page. Finally it displays the HTML Content in the browser.
HTTP - (Hyper Text Transfer Protocol) :
HTTP takes care of the communication between a web server and a web browser. HTTP is used for sending requests from a web client (a browser) to a web server, returning web content (web pages) from the server back to the client.
Where is my web server ?
When you try to access a web site, you don't really need to know where the web server is located. The web server may be located in another city or country, but all you need to do is, type the URL of the web site you want to access in a web browser. The web browser will send this information to the internet and find the web server. Once the web server is located, it will request the specific web page from the webserver program running in the server. Web server program will process your request and send the resulting web page to your browser. It is the responsibility of your browser to format and display the webpage to you.

How many web servers are needed for a web site?

Typically, there is only one web server required for a web site. But large web sites like Yahoo, Google, MSN etc will have millions of visitors every minute. One computer cannot process such huge numbers of requests. So, they will have hundreds of servers deployed in different parts of the world so that can provide a faster response.

How many websites can be hosted in one server?

A web server can hosted hundreds of web sites. Most of the small web sites in the internet are hosted on shared web servers. There are several web hosting companies who offer shared web hosting. If you buy a shared web hosting from a web hosting company, they will host your web site in their web server along with several other web sites for a Fee.

Examples of web server applications

1. IIS
2. Apache
Definitions of Web Server on the Web:
l     A software program that transforms an Internet-connected computer into a machine capable of hosting Web pages.
l     A computer, including software package, that provides a specific kind of service to client software running on other computers. More specifically, a server is a computer that manages and shares web based applications accessible anytime from any computer connected to the Internet.
l     A computer that uses software to transmit Web pages and associated files over the Internet.
l     A server that delivers web content to web browsers. Essentially a large computer, it can be Windows, Unix, Linux based and can hold many websites together which it shares with browsers via the internet infrastructure.
l     A computer connected to the Internet for the purpose of serving a web sites web pages to visitors on the world wide web.
l     A program that serves files to users so they can view web pages.
Definitions for browser
·       Browser is an application, which helps us to view the Web sites and the web content.
·       Web sites are located in some remote systems, which needs a special kind of program or an application to access them, such an application is called browser.
·       A browser is an application which you can use to retrieve web pages from web sites and view.
·       When you type a URL in the browser, the browser will convert it into a web request which web server can understand. Browser will send the request to web server using the HTTP protocol.
·       When a web server returns a web page as a Response, the browser will understand the response and display the body of the response to the user in browser.
·       In simple terms a browser can be defined as “A software application used to locate and display Web pages”
·       You can create your own simple browser application using C++, C#, VB.NET or any other language you like. All you need to know is, how to compose a request which web server can understand, how to parse and display the response from web server and communicate with webserver using HTTP protocol.
·       Even though the basic job of browser is just send requests to web server and receive response from the server, modern browser provide several other enhanced features including Back/Forward buttons, save viewed files to disk so that they can be viewed later, cache images so that the same images need not be downloaded again and again etc.
·       Internet Explorer, Netspace, Mozilla are some of the popular web browsers currently available in the market.
·       Netscape was the most popular web browser till 4-5 years back, but currently more than 90% of the internet users use "Internet Explorer" to browse the websites.

Windows Applications

If you don't know what is a 'Windows Application', probably you have never seen a computer. Almost any application you see on a desktop computer is called 'Windows Application'.
It is also called 'desktop applications' since they are mostly used in desktop computers.
Some common examples of desktop applications are:

1. Paint Brush program
2. Calculator program
MSN Messenger
4. Yahoo Messenger

The first three windows applications are written by some programmers sitting in Microsoft office and they give it free to all who buy Windows operating system. The Yahoo messenger is written by Yahoo programmers and they give it free to download from their web site.

If your neighbour ask you to write small 'Address book' application for his personal use, you are going to write a 'windows application'.
Web Applications
A web application is also called 'web site'. A web site is a collection of web pages hosted on a special computer called 'web server'.

Now you are reading this tutorial. This chapter is a page among several other pages part of our web application. The name of our web application is ''. This web site (web application) is running in our web server, which is located in a safe place in USA. You are a 'visitor' to our site and you are accessing our web application using a tool called 'Internet Explorer' (or, some other browser like Netscape etc). We don't know where you are (we have several ways to find it, which we will explain in some other chapter)
So, here is some interesting points about a web application :
·       A web application is a collection of web pages.
·       A web application needs a web server to run.
·       Web server can be located anywhere and visitors need not be even in the same country of the web server.
·       Visitors can access the web application using a tool called 'browser'. There are many browsers exists. Most widely used browser is 'Internet Explorer'. This is provided by Microsoft and it is free. Another famous free browser is 'Netscape'.