Professional Documents
Culture Documents
Session 02
Session 02
NET
Objectives
Ver. 1.0
Slide 1 of 29
In the earlier days of Web development, the programmers had to use HTML controls to design a Web application. The HTML controls do not provide any built-in methods and events. Programmers had to manually write the methods and events using client-side scripts to create a dynamic Web page. This is very time consuming. In addition, it is insecure because the client-side scripts are visible to users when they view the source for the Web page. ASP.NET solves the problems associated with the use of HTML controls by providing server controls.
Ver. 1.0
Slide 2 of 29
Server controls:
Are the fundamental building blocks that are specifically designed to work with Web forms in an ASP.NET application. Can be rendered as markup text on a Web browser. Are capable of executing the program logic on the server. Provide built-in methods and events eliminating the need for writing the events and methods manually. Provide security to the application by hiding the program logic from the user. Provide an object-oriented programmable interface. Can be viewed as special HTML tags, which are processed by the server.
Ver. 1.0
Slide 3 of 29
Ver. 1.0
Slide 4 of 29
When a page is requested for the first time, the server controls are processed in the following sequence:
1. 2. 3. 4. 5. 6. 7. Initializing Loading PreRendering Saving Rendering Disposing Unloading
Ver. 1.0
Slide 5 of 29
When the Web page is posted back to the Web server, the server controls are processed in the following sequence:
1. 2. 3. 4. 5. 6. 7. 8. 9. Initializing Loading view state Loading control instance Loading the postback data PreRendering Saving Rendering Disposing Unloading
Ver. 1.0
Slide 6 of 29
Ver. 1.0
Slide 7 of 29
The following table lists some of the common HTML server controls with their description.
HTML Server Controls HtmlAnchor control HtmlInputText control Description Works as the HTML <a> tag but runs on the server. It is used to direct the user from one page to another.
Works as the HTML <INPUT type="text"> tag but runs on the server. It is used to gather information from the user. HtmlInputCheckBox Works as the HTML <INPUT type="checkbox"> tag but runs on control the server. It is useful to implement questions that can have only two answers, such as yes/no or true/false HtmlInputRadioButton Works as the HTML <INPUT type="radio"> tag but runs on the control server. You can use the HtmlInputRadioButton control to implement multiple-choice questions, where a user can select only one option. HtmlSelect control Works as the HTML <select> element but it runs on the server. It is used to create a list box and when a user has to select an option from a list of options.
Ver. 1.0
Slide 8 of 29
Ver. 1.0
Slide 9 of 29
ImageButton control Button control Wizard control MultiView control HyperLink control FileUpload control XML control Substitution control
Ver. 1.0
Slide 10 of 29
Validation controls:
Are used for validating the values entered by the users in other controls.
ASP.NET provides the following validation controls that can be attached to input controls to validate the values that are entered by the user:
RequiredFieldValidator control RegularExpressionValidator control CompareValidator control RangeValidator control ValidationSummary control CustomValidator control
Ver. 1.0
Slide 11 of 29
Ver. 1.0
Slide 12 of 29
Event handlers:
When an event is raised, the corresponding event handler is searched and the code written in the event handler is executed. The various approaches that can be used to work with event handlers include:
Using default events. Using non-default events. Using the AutoEventWireup capabilities of a Web form. Creating centralized event-handlers.
Ver. 1.0
Slide 13 of 29
Ver. 1.0
Slide 14 of 29
Ver. 1.0
Slide 15 of 29
Ver. 1.0
Slide 16 of 29
Ver. 1.0
Slide 17 of 29
Ver. 1.0
Slide 18 of 29
There are situations where you need to add controls dynamically to a Web page. You can add the controls at run time. By adding controls to a Web page at run time makes a website flexible, interactive, and user-friendly. When adding a control dynamically to a Web page, you need to place them in a container, so as to make the Web page well-structured.
Ver. 1.0
Slide 19 of 29
Two controls that act as containers when adding controls dynamically are:
PlaceHolder: Is used as a container that is not visible in a Web application. It reserves a place in the structure of the Web page for other controls that are added dynamically Panel: Renders div tag around all the child controls in the panel, which makes it useful when you want to apply a css class to a container.
Ver. 1.0
Slide 20 of 29
An event handler for a control is usually created at design time. It can also be created dynamically at run time for the controls that are created dynamically.
Ver. 1.0
Slide 21 of 29
Problem Statement:
MusicMania is a music store with its branches located all over the United States. It has a huge collection of music albums to cater to the tastes of all kind of music lovers. To increase the sales, the management at MusicMania has decided to hire a team of professionals to develop a Web application for selling music online. You, being a part of the team, have been asked to create a file-system Web application. Initially, you are required to design the Home page and the About Us page.
Ver. 1.0
Slide 22 of 29
Solution:
To design the home page of the MusicMania Web application, you need to perform the following tasks:
1. Design the Home page. 2. Design the About Us page. 3. Execute the application.
Ver. 1.0
Slide 23 of 29
A generic handler can be used when you want to display the contents of a text file, an XML file, or an image. The generic handler provides a class that implements the IHttpHandler interface. The class provides the ProcessRequest method and the IsReusable property. The ProcessRequest method is responsible for processing individual HTTP requests. The IsReusable property specifies whether the IHttpHandlerFactory object can put the handler in a pool and reuse it to increase performance. The IHttpHandlerFactory object is the object that calls the appropriate handler.
Let us see how to create a generic handler
Ver. 1.0
Slide 24 of 29
Ver. 1.0
Slide 25 of 29
The sequence in which a server control is processed when the page is requested for the first time is:
1. 2. 3. 4. 5. 6. 7. Initializing Loading PreRendering Saving Rendering Disposing Unloading
Ver. 1.0
Slide 26 of 29
The sequence in which a server control is processed when the Web page is posted back to the Web browser is:
1. 2. 3. 4. 5. 6. 7. 8. 9. Initializing Loading view state Loading control instance Loading the postback data PreRendering Saving Rendering Disposing Unloading
Ver. 1.0
Slide 27 of 29
The various types of server controls provided by ASP.NET can be classified into the following categories:
HTML server controls Web server controls Validation controls User controls
An event is a message that contains details about the user action, such as the cause of the event and the control on which the event occurred. The two arguments passed by all events in ASP.NET are:
Sender object Event object
The two types of events in ASP.NET server control event model are:
Postback events Nonpostback events
Ver. 1.0
Slide 28 of 29
The two controls that act as container when adding controls dynamically are:
PlaceHolder Panel
Ver. 1.0
Slide 29 of 29