Introduction to ASP.NET iFour Consultancy
https://www.ifourtechnolab.com/aspdotnet-web-development
•A markup language is a set of markup tags
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)
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Web Pages What 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
https://www.ifourtechnolab.com/aspdotnet-web-development
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
https://www.ifourtechnolab.com/aspdotnet-web-development
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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Master Pages ďƒ˜ 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>
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Controls 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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : HTML Server controls 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 control For Eg: <input type=“text” size=“20” id=“txtName” runat=“Server” />
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Server controls 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” />
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Validation controls 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”/>
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : User and Custom Controls 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" />
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : User and Custom Controls Custom controls
Custom 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>
https://www.ifourtechnolab.com/aspdotnet-web-development
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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Page life cycle events 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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : State Management 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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Client Side State Management
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 inmemory 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
https://www.ifourtechnolab.com/aspdotnet-web-development
Introduction to ASP.NET : Server Side State Management
Application State
Session 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 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. https://www.ifourtechnolab.com/aspdotnet-web-development
Thank You..
https://www.ifourtechnolab.com/aspdotnet-web-development