overview of asp.net by software outsourcing company india

18
iFour Consultancy Introduction to ASP.Net

Upload: jignesh-aakoliya

Post on 20-Jan-2017

40 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Overview of ASP.Net by software outsourcing company india

iFour Consultancy

Introduction to ASP.Net

Page 2: Overview of ASP.Net by software outsourcing company india

Introduction to ASP.Net : Basics

What Is ASP.Net?• ASP.Net is a 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#.

• ASP.Net is 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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 3: Overview of ASP.Net by software outsourcing company india

Introduction to ASP.Net : Web Pages

What is Web Pages?• Web Pages is one of the 3 programming models for creating ASP.NET web sites and web

applications.• Web Pages is the 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.

• It provides an easy way to combine HTML, CSS, JavaScript and server code.

Custome Commerce Solution Providershttp://www.ifourtechnolab.com http://www.ifourtechnolab.com

Page 4: Overview of ASP.Net by software outsourcing company india

Introduction to ASP.Net : Web Pages

ASP.NET Web Pages 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. Dynamic pages like those you create with ASP.NET Web Pages let you create the page content on the fly, by using code.

Dynamic pages let you do all sorts of things. You can ask a user for input by using a form and then change what the page displays or how it looks. You can take information from a user, save it in a database, and then list it later. You can send email from your site. You can interact with other services on the web (for example, a mapping service) and produce pages that integrate information from those sources.

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 5: Overview of ASP.Net by software outsourcing company india

Introduction to ASP.Net : Master Pages

• Master pages provide templates for other pages on your web site.• Master pages allow you to create a consistent look and behavior for all the pages

(or group of pages) in your web application.• A master page provides a template for other pages, with shared layout and

functionality.• The master page 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 you want to display.

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 6: Overview of ASP.Net by software outsourcing company india

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" />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>

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>

Introduction to ASP.Net : Master Pages

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 7: Overview of ASP.Net by software outsourcing company india

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.

Controls are also 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 controlsASP.NET Server controlsASP.NET Validation controlsUser controls and custom controls

Introduction to ASP.Net : Controls

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 8: Overview of ASP.Net by software outsourcing company india

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

For Eg: <input type=“text” size=“20” id=“txtName” runat=“Server” />

Introduction to ASP.Net : HTML Server controls

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 9: Overview of ASP.Net by software outsourcing company india

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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 10: Overview of ASP.Net by software outsourcing company india

After you create a web form, you should make sure that mandatory fields of the form elements such as login name and password are not left blank; data inserted is correct and is within the specified range. Validation is the method of scrutinizing (observing) that the user has entered the correct values in input fields.

A Validation server control is used to validate the data of an input control. If the data does not pass validation, it will display an error message to the user.

In ASP. NET you can use ASP. NET Validation Controls while creating the form and specify what ASP. NET Validation Controls you want to use and to which server control you want bind this.

Validation Controls are derived from a common base class and share a common set of properties and methods. You just have to drag and drop the ASP. NET Validation Control in the web form and write one line of code to describe its functionality.

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

Validation Controls used in ASP.Net: CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, ValidationSummary

Introduction to ASP.Net : Validation controls

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 11: Overview of ASP.Net by software outsourcing company india

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

User ControlsUser 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" %>

Implemtation<%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>

<Tfooter:footer ID="footer1" runat="server" />

Introduction to ASP.Net : User and Custom Controls

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 12: Overview of ASP.Net by software outsourcing company india

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 controlBy 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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 13: Overview of ASP.Net by software outsourcing company india

Introduction to ASP.Net : Page life cycle When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include

initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering.

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), or whether a cached version of the page can be sent in response without running the 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. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

• 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. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)

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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 14: Overview of ASP.Net by software outsourcing company india

At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.

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. The Init event of individual controls occurs before the Init event

of the page.• InitComplete - Raised at the end of the page's initialization stage. Only one operation takes place between the Init and InitComplete events : tracking of

view state changes is turned on.• 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. The Load event of individual controls occurs after the Load event of the page.• 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. All ASP.NET Web server controls have

a Render method that writes out the control's markup to send to the browser.• UnLoad - Raised for each control and then for the page.

Introduction to ASP.Net : Page life cycle events

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 15: Overview of ASP.Net by software outsourcing company india

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 you preserve 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

View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways. However, application state, session state, and profile properties all store data in memory on the server. Each option has distinct advantages and disadvantages, depending on the scenario.

Introduction to ASP.Net : State Management

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 16: Overview of ASP.Net by software outsourcing company india

View State - The ViewState property 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 - The ControlState property allows you to persist property information that is specific to a control and cannot be turned off like the ViewState property.

Hidden Fields - ASP.NET allows you 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, but you can set its properties just as you can with a standard control.

Cookies - A cookie is a 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. It contains site-specific information that the server sends to the client along with page output. Cookies can be temporary (with specific expiration times and dates) or persistent.

Query Strings - A query string 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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 17: Overview of ASP.Net by software outsourcing company india

Application State - Application state is a global storage mechanism that is accessible from all pages in the Web application. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages.

Session State - Session state is 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 - ASP.NET provides a feature called profile properties, which allows you to 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. The profile-properties 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

Custome Commerce Solution Providershttp://www.ifourtechnolab.com

Page 18: Overview of ASP.Net by software outsourcing company india

Thank you

Software development company indiahttp://www.ifourtechnolab.com