asp.net by ifour technolab pvt. ltd

20
iFour Consultancy Introduction to ASP.NET

Upload: ifour-institute-sustainable-learning

Post on 11-Apr-2017

47 views

Category:

Software


0 download

TRANSCRIPT

Page 1: asp.net by iFour Technolab Pvt. Ltd

iFour Consultancy

Introduction to ASP.NET

Page 2: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET Web Pages Master Pages Controls HTML Server controls Server controls Validation controls User and Custom Controls Page life cycle Page life cycle events State Management Client Side State Management Server Side State Management

INDEX

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 3: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET : Basics

What Is ASP.NET?• Web development platform, which provides a programming model, a comprehensive software

infrastructure and various services required to build up robust web application for PC, as well as mobile devices

• ASP.Net works on top of the HTTP protocol and uses the HTTP commands and policies to set a browser-to-server two-way communication and cooperation

• The ASP.net application code could be written in different languages like C#, visual basic .NET, Jscript, J#

• Used to produce interactive, data-driven web applications over the internet• ASP.NET pages have the extension .aspx, and are normally written in VB (Visual Basic) or C# (C

sharp)

•A markup language is a set of markup tags

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 4: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET : Web PagesWhat is Web Pages?

• One of the programming models for creating ASP.NET web sites and web applications• Simplest programming model for developing ASP.NET web pages• Advantages:

Easy to learn, understand, and use Built around single web pages Similar to PHP and Classic ASP Server scripting with Visual Basic or C# Full HTML, CSS, and JavaScript control

• Provides an easy way to combine HTML, CSS, JavaScript and server code

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 5: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET : Web Pages

It is a framework that you can use to create dynamic web pages A simple HTML web page is static, its content is determined by the fixed HTML markup

that's in the page Take information from a user, save it in a database, and then list it later. Interact with other services on the web (for example, a mapping service) and produce

pages that integrate information from those sources

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 6: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET : Master Pages

Provide templates for other pages on your web site It allow to create a consistent look and behavior for all the pages (or group of pages) in

web application Provides a template for other pages, with shared layout and functionality It defines placeholders for the content, which can be overridden by content pages. The

output result is a combination of the master page and the content page The content pages contain the content to display

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 7: asp.net by iFour Technolab Pvt. Ltd

Master Page(filename Master1.master) :<%@ Master Language="C#" %><!DOCTYPE html ><html xmlns="http://www.w3.org/1999/xhtml" ><body> <form id="form1" runat="server">

<div> <asp:contentplaceholder id="Main" runat="server" /> </div>

<div> <asp:contentplaceholder id="Footer" runat="server" /> </div> </form></body></html>

Introduction to ASP.NET : Master Pages

Content Page:<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">

Main content.

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >

Footer content.

</asp:content>

Example: The directive used for master page is <%@ Master Language="C#" %> and for variable content to display in different pages

content place holder is declared as <asp:contentplaceholder id="Main" runat="server" />

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 8: asp.net by iFour Technolab Pvt. Ltd

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 Used for structural jobs, like validation, data access, security, creating master pages, and data

manipulation ASP.NET uses five types of web controls, which are:

ASP.NET HTML Server controls ASP.NET Server controls ASP.NET Validation controls ASP.NET Ajax Server controls User controls and custom controls

Introduction to ASP.NET : Controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 9: asp.net by iFour Technolab Pvt. Ltd

ASP.NET provides a way to work with HTML Server controls on the server side; programming with a set of controls collectively is called HTML Controls.

These controls are grouped together in the Visual Studio Toolbox in the HTML Control tab. The markup of the controls are similar to the HTML control

These controls are basically the original HTML controls but enhanced to enable server side processing

HTML elements in ASP. NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server controlFor Eg: <input type=“text” size=“20” id=“txtName” runat=“Server” />

Introduction to ASP.NET : HTML Server controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 10: asp.net by iFour Technolab Pvt. Ltd

Server controls are special ASP. NET tags understood by the server Like HTML server controls, Web server controls are also created on the server and they

require a runat="server" attribute to work However, Web server controls do not necessarily map to any existing HTML elements and

they may represent more complex elements Mostly all Web Server controls inherit from a common base class, namely the WebControl

class defined in the System.Web.UI.WebControls namespace Example of a server control:

<asp:TextBox ID=“txtName” runat=“server” />

Introduction to ASP.NET : Server controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 11: asp.net by iFour Technolab Pvt. Ltd

Validation is the method of scrutinizing (observing) that the user has entered the correct values in input fields

Used to validate the data of an input control. If the data doesn’t pass validation, it will display an error In ASP. NET you can use ASP. NET Validation Controls while creating the form and specify what ASP. NET

Validation Controls to use and to which server control to bind this Validation Controls are derived from a common base class and share a common set of properties and

methods. Drag and drop the ASP. NET Validation Control in the web form and write one line of code to describe its

functionality Validation Controls in ASP.NET: CompareValidator, CustomValidator, RangeValidator,

RegularExpressionValidator, RequiredFieldValidator, ValidationSummary Example of validation control :

<asp:RequiredFieldValidator ID=“rfvName” runat=“server” ControlToValidate=“txtName” ErrorMessage=“Name is required”/>

Introduction to ASP.NET : Validation controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 12: asp.net by iFour Technolab Pvt. Ltd

ASP.NET allows the users to create controls. These user defined controls are categorized into: User controls Custom controls

User Controls User controls behaves like miniature ASP.NET pages or web forms, which could be used by many other pages. These are

derived from the System.Web.UI.UserControl class. These controls have the following characteristics: They have an .ascx extension They may not contain any <html>, <body>, or <form> tags They have a Control directive instead of a Page directive

Example: Declaration of custom controls <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="footer.ascx.cs" Inherits="customcontroldemo.footer" %>

Implementation:On top of the page, have to register the control as follows:<%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>Following is the tag declaration for showing the user control<Tfooter:footer ID="footer1" runat="server" />

Introduction to ASP.NET : User and Custom Controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 13: asp.net by iFour Technolab Pvt. Ltd

Custom controlsCustom controls are deployed as individual assemblies. They are compiled into a Dynamic Link

Library (DLL) and used as any other ASP.NET server control. They could be created in either of the following way:

By deriving a custom control from an existing control By composing a new custom control combing two or more existing controls By deriving from the base control class

Example of using a Custom Control<%@ Register Assembly="CustomControls" Namespace="CustomControls" TagPrefix="ccs" %>

<form id="form1" runat="server">

<div>

<ccs:ServerControl1 runat="server" Text = "I am a Custom Server Control" />

</div>

</form>

Introduction to ASP.NET : User and Custom Controls

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 14: asp.net by iFour Technolab Pvt. Ltd

Introduction to ASP.NET : Page life cycle

The page life cycle phases are:• Page request - The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET

determines whether the page needs to be parsed and compiled (therefore beginning the life of a page)• Start - In the start stage, page properties such as Request and Response are set. At this stage, the page also determines

whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property

• Initialization - During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable

• Load - During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state

• Postback event handling - If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page

• Rendering - Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property

• Unload - The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 15: asp.net by iFour Technolab Pvt. Ltd

Following are the page life cycle events:• PreInit - Raised after the start stage is complete and before the initialization stage begins• Init - Raised after all controls have been initialized and any skin settings have been applied• InitComplete - Raised at the end of the page's initialization stage. Only one operation takes place between the Init and InitComplete

events• PreLoad - Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with

the Request instance• Load - The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until

the page and all controls are loaded• LoadComplete - Raised at the end of the event-handling stage• PreRender - Raised after the Page object has created all controls that are required in order to render the page, including child

controls of composite controls• PreRenderComplete - Raised after each data bound control whose DataSourceID property is set calls its DataBind method• SaveStateComplete - Raised after view state and control state have been saved for the page and for all controls. Any changes to the

page or controls at this point affect rendering, but the changes will not be retrieved on the next postback• Render - This is not an event; instead, at this stage of processing, the Page object calls this method on each control• UnLoad - Raised for each control and then for the page

Introduction to ASP.NET : Page life cycle events

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 16: asp.net by iFour Technolab Pvt. Ltd

A new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, this would typically mean that all information associated with the page and the controls on the page would be lost with each round trip

For example, if a user enters information into a text box, that information would be lost in the round trip from the browser or client device to the server

To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options that help preserves data on both a per-page basis and an application-wide basis

These features are as follows: View state Control state Hidden fields Cookies Query strings Application state Session state Profile Properties

Introduction to ASP.NET : State Management

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 17: asp.net by iFour Technolab Pvt. Ltd

View State - Provides a dictionary object for retaining values between multiple requests for the same page. This is the default method that the page uses to preserve page and control property values between round trips

Control State - It allows to persist property information that is specific to a control and cannot be turned off like the ViewState property

Hidden Fields - ASP.NET allows to store information in a HiddenField control, which renders as a standard HTML hidden field. A hidden field does not render visibly in the browser

Cookies - Small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. Cookies can be temporary (with specific expiration times and dates) or persistent

Query Strings - It is information that is appended to the end of a page URL. A typical query string might look like the following example: http://www.Example.com/stateManagement.aspx?q1=basic&q2=100

Introduction to ASP.NET : Client Side State Management

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 18: asp.net by iFour Technolab Pvt. Ltd

Application State Global storage mechanism that is accessible from all pages in the Web application Used for storing information that needs to be maintained between server round trips and between requests for pages

Session State Similar to application state, except that it is scoped to the current browser session. If different users are using your

application, each user session will have a different session state In addition, if a user leaves your application and then returns later, the second user session will have a different

session state from the first Profile Properties

Store user-specific data. This feature is similar to session state, except that the profile data is not lost when a user's session expires

This feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database.

Introduction to ASP.NET : Server Side State Management

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 19: asp.net by iFour Technolab Pvt. Ltd

https://www.tutorialspoint.com/asp.net/ http://www.w3schools.com/asp/ https://msdn.microsoft.com/en-us/library/4w3ex9c2.aspx

References

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India

Page 20: asp.net by iFour Technolab Pvt. Ltd

Questions?

http://www.ifourtechnolab.com/

ASP.NET Software Development Companies India