1 / 44

Introduction to ASP.NET

Introduction to ASP.NET. What is .NET What is ASP.NET and how is different from ASP ASP: server side technology for creating dynamic web pages using scripting languages eg vb script.

quasim
Download Presentation

Introduction to ASP.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to ASP.NET • What is .NET • What is ASP.NET and how is different from ASP • ASP: server side technology for creating dynamic web pages using scripting languages eg vb script. • ASP.NET: server side technology for creating dynamic web pages using Fully Fledged programming languages supported by .NET • VB.NET: our chosen language for writing ASP.NET pages

  2. What is .NET? • A Microsoft strategy and new technology for delivering software services to the desktop and to the web • Components include: • MS Intermediate Language; all code is complied into a more abstract, trimmed version before execution. All .NET languages are compiled to MSIL – the common language of .NET • The CLR- common language runtime; responsible for executing MSIL code; interfaces to Windows and IIS • A rich set of libraries (Framework Class Libraries) available to all .NET languages • The .NET languages such as C#, VB.NET etc that conform to CLR • ASP.NET is how the Framework is exposed to the web, using IIS to manage simple pages of code so that they can be complied into full .NET programs. These generate HTML for the browser. • Built on open protocols (XML, SOAP) • Future for development of MS & non-MS based systems. Such as Linux, Unix…

  3. Common Language Runtime Type System Compilers use the runtime type system to produce type compatiblecomponents Components C# VB C++ Compilers Runtime Environment Common Type System

  4. Robust And Secure • Native code compilation • MSIL • No interpreter • Install-time or run-time IL to native compilation • Code correctness and type-safety • IL can be verified to guarantee type-safety • No unsafe casts, no non-initialized variables, no out-of-bounds array indexing • Evidence-based security • Policy grants permissions based on evidence (signatures, origin)

  5. .NET Execution Model VB VC ... Script NativeCode MSIL Common Language Runtime Standard JITCompiler NativeCode

  6. Common Language Runtime • Lightweight Just-in-time compiler: • MSIL(Intermediate language) to Native machine language • Can be ported to numerous platforms • Free/Net BSD UNIX port has been announced • “MONO” Open source movement

  7. Framework Overview VB C++ C# JScript … Visual Studio.NET Common Language Specification Web Forms (ASP.NET) Win Forms Data and XML Base Class Library Common Language Runtime

  8. .NET Framework Architecture System.WinForms System.Web Controls Drawing Web Services Web Forms Windows Application Services ASP.NET Application Services System Base Framework ADO.NET XML SQL Threading IO Net Security ServiceProcess Common Language Runtime Type System Metadata Execution

  9. ASP.NET • ASP.NET provides a means of exposing the .NET Framework and its functionality to the WWW • Contains a number of pre-built types that take input from .NET types and represents them in a form for the web (such as HTML) • Example: http://academic1.bellevue.edu/asp.net/examples/lesson11/(ve32xyu1a1303kb4ji53xxqi)/default.aspx http://academic1.bellevue.edu/showtables/default.aspx

  10. ASP.NET • High developer productivity • Great performance and reliability • Fast deployment.

  11. Easy Programming Model • ASP.NET makes building real world Web applications dramatically easier.  ASP.NET server controls enable an HTML-like style of declarative programming that let you build great pages with far less code than with classic ASP.  Displaying data, validating user input, and uploading files are all amazingly easy.  Best of all, ASP.NET pages work in all browsers -- including Netscape, Opera, AOL, and Internet Explorer

  12. Flexible Language Options • ASP.NET lets you leverage your current programming language skills.  Unlike classic ASP, which supports only interpreted VBScript and JScript, ASP.NET now supports more than 25 .NET languages (including built-in support for VB.NET, C#, and JScript.NET -- no tool required), giving you unprecendented flexibility in your choice of language.

  13. Great Tool Support • You can harness the full power of ASP.NET using any text editor -- even Notepad!  But Visual Studio .NET adds the productivity of Visual Basic-style development to the Web.  Now you can visually design ASP.NET Web Forms using familiar drag-drop-doubleclick techniques, and enjoy full-fledged code support including statement completion and color-coding.  

  14. Rich Class Framework • Application features that used to be hard to implement, or required a 3rd-party component, can now be added in just a few lines of code using the .NET Framework.  The .NET Framework offers over 4500 classes that encapsulate rich functionality like XML, data access, file upload, regular expressions, image generation, performance monitoring and logging, transactions, message queuing, SMTP mail, and much more!

  15. Performance and Scalability • ASP.NET is much faster than classic ASP, while preserving the "just hit save" update model of ASP.  However, no explicit compile step is required!  ASP.NET will automatically detect any changes, dynamically compile the files if needed, and store the compiled results to reuse for subsequent requests.

  16. Performance and Scalabilitycont. • Rich output caching • Web-Farm Session State • Microsoft .NET Outperforms J2EE

  17. Reliability • Memory Leak, DeadLock and Crash Protection.  ASP.NET automatically detects and recovers from errors like deadlocks and memory leaks to ensure your application is always available to your users. 

  18. Easy Deployment • "No touch" application deployment. .NET dramatically simplifies installation of your application. • Dynamic update of running application.  ASP.NET now lets you update compiled components without restarting the server. • Easy Migration Path.  You don't have to migrate your existing applications to start using ASP.NET. 

  19. Web Services • Web Services also provide a means to expose .NET functionality on the web but Web Services expose functionality via XML and SOAP (cf: function calls over the web)

  20. How ASP.NET works • When .NET is installed, IIS is configured to look for files with the .aspx extension and to use the ASP.NET module (aspnet_isapi.dll) to handle them. • ASP.NET parses the .aspx file and arranges it in a predefined class definition and generates an asp.net page object. • The page object generates html that is sent back to IIS and then the browser. • NOTE: only .aspx files are parsed (if it is pure html don’t save it as an aspx file as it will slow down the server.

  21. ASP.NET samples • Page directives: <%@ page language = “VB” debug="true" trace="true“ %> • <script language = “VB” runat=“server”> VB.NET code declarations ……….. </script> • test.html or test.aspx <html> <head> <title>Code Example</title> </head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> </body> </html> • Note this has no asp code so better to use .html extension

  22. test2.aspx <script language="VB" runat="server"> Sub Page_Load() Response.Write ("First ASP.NET Line<br />") Response.Write ("Second ASP.NET Line<br />") Response.Write ("Third ASP.NET Line<br />") End Sub </script> <html> <head> <title>Inserting ASP.NET code Example</TITLE> </head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> </body> </html>

  23. test3.aspx html> <head><title>Inserting ASP.NET code Example</title></head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> <script language="VB" runat="server"> Sub Page_Load() Response.Write ("First ASP.NET Line<br />") Response.Write ("Second ASP.NET Line<br />") Response.Write ("Third ASP.NET Line<br />") End Sub </script> </body> </html>

  24. ASP.NET Form • An ASP.NET form is a HTML form plus asp.net code in the form of server controls. • ASP.NET form has extra functionality to maintain form data or state (_VIEWSTATE) eg text in a text box • Hidden variable to store ‘coded’ version of the form • ASP.NET server controls duplicate the functionality of many HTML elements. • Take the form of an html-like tag, marking the point in the page where the server needs to generate corresponding true HTML elements. (produces server side object that can be manipulated at any part of the code.)

  25. Web Forms • Server side controls • Generate output suitable for the browser • Preserves state across page refreshes (Viewstate) • Raise server side events • Used as the base to build richer controls • ASP.Net includes a range of useful classes and namespaces • Namespace is like a class library eg. System.Web.UI.HtmlControls

  26. Server side controls • HTMLControls • System.Web.UI.HtmlControls namespace • Can be directly mapped to HTML tags • Used for backward compatibility with ASP eg <input type=“text” runat=“server” id=“txtname” value=“mytext” > • Web Controls • System.Web.UI.WebControls namespace • Form based event model eg buttonclick • Offer a richer set of controls • implement a number of common properties (properties through class browser) • data binding • automatic browser detection <asp:textbox id=“txtname” runat=“server” text=“mytext”> • Programmatic reference of a control is by the unique id attribute eg id=“txtname”

  27. How do server controls work? • Declared with the runat=“server” attribute • when the aspx page is executed • creates Action and Method attributes of the form • adds unique Id and Name attributes to controls • adds Value attribute to controls • adds a hidden control (_VIEWSTATE) to the form to save form state information

  28. Example <script runat="server" language="vb"> Sub Page_Load() if Request.Form("list1") <> "" then Message.text = "You have selected " + Request.Form("list1") end if End Sub </script> <html> <head> <title>Drop Down List Example</title> </head> <body> <asp:label id="message" runat="server"/> <br /> <form runat="server"> <!– notice no action or method attributes --> Which city do you wish to look at hotels for?<br /><br /> <asp:dropdownlist id="list1" runat="server"> <asp:listitem>Madrid</asp:listitem> <asp:listitem>Oslo</asp:listitem> <asp:listitem>Lisbon</asp:listitem> </asp:dropdownlist> <br /><br /><br /><br /> <input type="Submit"> </form> </body> </html>

  29. Output

  30. Output 2

  31. Output 2 source code in HTML <html> <head> <title>Drop Down List Example</title> </head> <body> <span id="message">You have selected Lisbon</span> <br /> <form name="_ctl0" method="post" action="listpage.aspx" id="_ctl0"> <input type="hidden" name="__VIEWSTATE" value="dDwtMTMyNTU5Mzc0Njt0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8WW91IGhhdmUgc2VsZWN0ZWQgTGlzYm9uOz4+Oz47Oz47Pj47PtM3XxNyv4v6En+WgxP4D5/iJj1M" /> Which city do you wish to look at hotels for?<br /><br /> <select name="list1" id="list1"> <option value="Madrid">Madrid</option> <option value="Oslo">Oslo</option> <option selected="selected" value="Lisbon">Lisbon</option> </select> <br /><br /><br /><br /> <input type="Submit"> </form> </body> </html>

  32. Output 2 source code cont. • All output from server to browser is HTML • New attributes added to form tag • <form name="_ctl0" method="post" action="listpage.aspx" id="_ctl0"> • Post is the asp.net default method • Action attribute points to the same page (listpage.aspx) • A hidden control stores the state of the page <input type="hidden" name="__VIEWSTATE" value="dDwtMTMyNTU5Mzc0Njt0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8WW91IGhhdmUgc2VsZWN0ZWQgTGlzYm9uOz4+Oz47Oz47Pj47PtM3XxNyv4v6En+WgxP4D5/iJj1M" /> • Used by asp.net to keep track of all server control settings from one page refresh to another; otherwise listbox would revert to static default setting every time page is loaded. Very useful for data validation.

  33. Web controls • There are five types of controls • Intrinsic Controls eg asp:list, asp:button etc • List Controls eg asp:datagrid, asp:datarepeater • Rich Controls eg asp:calander • Validation Controls eg asp:rangeValidator • Custom Controls – user defined • They support properties, methods and events

  34. Web control events • Each web control has a number of events (onClick…etc) • There are events associated with server events (Page_load..etc) • Each event results in a reload of the page via a postback • A web control is asociated to an event by setting its attributes - the name of the function which implements the event handler.

  35. Page event life circle • In ASP.NET a structured set of events occurs every time a page is viewed. The order is: • Page_init (done once; useful for variable initialisation) • Page_load (can be used to load data into controls from server DB) see POSTBACK • Change events eg textbox1_changed; by default only click events submit form to the server; change events are queued till then. (Some controls have an AUTOPOSTBACK property which will force a post) • Click event eg button1_click • Page_Unload (last event before page is discarded eg user going to another page; useful for closing files, db’s etc

  36. Example <%@ Page Language="vb" %> <HTML> <body> <SCRIPT language="VB" runat="Server"> Sub GreetMe(s As Object, e As EventArgs) label1.Text = "Hello " & txtName.Value & _ ". I see your occupation is " & lstTitle.Value End Sub </SCRIPT> <FORM runat="server"> Name: <INPUT type="text" id="txtName" runat="server"> <p>Profession: <SELECT id="lstTitle" runat="server"> <OPTION> Software Engineer </OPTION> <OPTION> Software Tester </OPTION> <OPTION> Program Manager </OPTION> </SELECT> <p><INPUT type="Submit" Value="Save" onServerClick="GreetMe" runat="server"> <p><asp:label id="label1" runat="server"/> </FORM> </body> </html>

  37. Output

  38. Configuration and Deployment • Configuration details are in a text file called web.config that is structured in XML format. This is in the site’s root folder • All files that a Web application needs are in folder under the site’s root folder and DLL’s are in the /bin folder (don’t have to register in the Registry; only need to copy) /wwwroot /webapplication1 - aspx, web.config /bin - dll’s /webapplication2 - aspx, web.config /bin - dll’s

  39. ASP.NET Vs PHP

  40. ASP.NET Summary Writing dynamic, high-performance Web applications has never been easier by using ASP.NET

More Related