1 / 44

ASP.NET

ASP.NET. طراحي صفحات وب پويا (برنامه نويسي پيشرفته سمت سرور و كلاينت). Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society. ASP. The leading web app development platform Nearly 1 million developers using ASP today

livia
Download Presentation

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. ASP.NET طراحي صفحات وب پويا (برنامه نويسي پيشرفته سمت سرور و كلاينت) Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society

  2. ASP • The leading web app development platform • Nearly 1 million developers using ASP today • Simple and approachable model for web developers to get started • No compilers required –“just hit save” • Easy to use languages and object model • Well established developer support base • Good book/consulting/conference support IT Scientific Society - December 2006

  3. ASP, JSP, PHP, etc. • Way too much code required • Simple tasks often not easy • Poor re-use/encapsulation model • Applications contain spaghetti code • Intermixed html/code • Messy include files for re-use • Hacky page activation techniques • Limited language support • Latebound scripting only • JSP – Java only IT Scientific Society - December 2006

  4. ASP, JSP, PHP, etc. • Weak tools • Poor layout, debuggers, profilers, etc • Confusing security architecture • Doesn’t work well for Internet apps • Poor deployment • COM components a nightmare • Metabase configuration options confusing • Scalability challenges • No web farm or caching infrastructure IT Scientific Society - December 2006

  5. Introducing ASP.NET • ASP.NET is a revolutionary advance of ASP • Your existing ASP skills still work fine • But lots more features to leverage • Core themes that ASP.NET has focused on: • Making it easier to build web apps • Making it easier to deploy web apps • Making it easier to operate web apps • Providing great performance and scalability • Supported platforms • Windows NT 4 / IIS 4, Windows 2000 / IIS 5, ++ • Open hosting APIs IT Scientific Society - December 2006

  6. ASP.NET Pages (1 of 2) • Makes it dramatically easier to build dynamic web pages • Simplify common tasks done today • Validation, Data Manipulation, PostBack, State • Enable better support for different clients • Enable better uplevel/downlevel scenarios • Enable rich support for small devices • Enable cleaner code organization • Code no longer has to be mixed with HTML • Developers/designers can work independently IT Scientific Society - December 2006

  7. ASP.NET Pages (2 of 2) • Declarative server-side UI control model: <asp:datagrid id=“List1” backcolor=red runat=server> • Great way to encapsulate functionality • Zero coding required for common scenarios • Can automatically “Render” HTML to client • Rich extensibility model for 3rd party innovations • Extend from our server controls • Replace features, e.g. SessionState IT Scientific Society - December 2006

  8. What is the .NET Framework? Developer Tools Clients ASP.NET Web Applications Databases XML Web Services User Experiences .NET Framework IT Scientific Society - December 2006

  9. Benefits of .NET • Based on Web standards and practices • Functionality of .NET classes is universally available • Code is organized into hierarchical namespaces and classes • Language independent • Solves existing problems: • Even with the Internet, most applications and devices have trouble communicating with each other • Programmers end up writing infrastructure instead of applications • Programmers have had to limit their scope or continually learn new languages IT Scientific Society - December 2006

  10. Data & XML Libraries Data & XML Libraries Data & XML Libraries Base Class Libraries Base Class Libraries Base Class Libraries Web Applications Web Applications Windows Applications Common Language Runtime Common Language Runtime Common Language Runtime .NET Framework Common Language Runtime IT Scientific Society - December 2006

  11. Message Queuing COM+ (Transactions, Partitions, Object Pooling) IIS WMI The .NET Framework Components Visual Basic C++ C# Perl Python … XML Web Services User Interface ASP.NET ADO.NET and XML .NET Framework Class Library Common Language Runtime Win32 IT Scientific Society - December 2006

  12. The Common Language Runtime • One runtime for all . NET-Based Languages • Manages threads and memory • Garbage collection • Enforces code security • Eliminates DLL versioning problems • Multiple versions of a DLL can run simultaneously • Applications can specify a version of a DLL to use IT Scientific Society - December 2006

  13. Using the Class Library • The class library is a set of classes (properties and methods) that all .NET applications can use • You use objects by referencing the .NET namespaces • Using a namespace in C#: • Implicit object declaration • Explicit object declaration using namespace_name; using System.Web.UI.WebControls; ListBox ListBox1; ListBox1.Items.Add("First Item"); System.Web.UI.WebControls.ListBox ListBox1; ListBox1.Items.Add("First Item"); IT Scientific Society - December 2006

  14. Framework • System • System.Collections • System.Data • System.Drawing • System.Diagnostics • System.DirectoryServices • System.Globalization • System.IO • System.Messaging • System.Net • System.Threading • System.Text • System.Reflection • System.Security • System.WinForms • System.Web • System.XML IT Scientific Society - December 2006

  15. Multiple Language Support • The .NET Framework is designed to support many languages • More than 20 languages currently supported • Microsoft provides Visual Basic .NET, C#, Visual J# .NET, and JScript .NET • Benefits of multiple-language support • Code modules are reusable • Class Library access is the same for all languages • The right language is used for the right task • Performance is roughly equal between all languages IT Scientific Society - December 2006

  16. Choosing a Language • .NET Framework class library is the same regardless of language • Performance • All languages are compiled to MSIL • Only performance difference is how each language compiler compiles to MSIL • The runtime compiles all MSIL the same, regardless of its origin • Development experience • C# is similar to Java, C, Visual C++, and Pascal • Visual Basic .NET is similar to Visual Basic • Browser compatibility • ASP.NET code is server-side code, so browser compatibility is not an issue IT Scientific Society - December 2006

  17. Overview of ASP.NET IT Scientific Society - December 2006

  18. ASP Web Application Architecture Presentation Tier ASP Page (.asp) UI Pages (.htm) Graphic Files Business Logic Tier COMObjects COM+Services ADO Data Tier Data Source IT Scientific Society - December 2006

  19. ASP.NET Web Application Architecture Presentation Tier Web Form (.aspx) UI Pages(.htm) User Controls(.ascx) Code-Behind File(.aspx.vb or .aspx.cs) Graphic Files Business Logic Tier RCW Proxy ADO.NET XML Web Services(.asmx) .NET Objects COMObjects COM+Services Data Tier Data Source IT Scientific Society - December 2006

  20. Which language? Visual Basic .NETcompiler MSIL C#compiler JITcompiler ASP.NET Runtime Compilation and Execution default.aspx C# Visual Basic .NET HTML Common Language Runtime Nativecode IT Scientific Society - December 2006

  21. Multimedia: ASP.NET Execution Model IT Scientific Society - December 2006

  22. Creating an ASP.NET Web Form IT Scientific Society - December 2006

  23. Demonstration: Developing an ASP.NET Web Application • Create a Web application • Add controls to a Web Form • View the HTML generated • Add an event procedure IT Scientific Society - December 2006

  24. What Is a Web Form? • .aspx extension • Page attributes • @ Page directive • Controls save state • Body attributes • Form attributes <%@ Page Language="C#" Inherits=Project.WebForm1 %> <html> <body ms_positioning="GridLayout"> <form id="Form1" method="post" runat="server"> </form> </body> </html> IT Scientific Society - December 2006

  25. What is a Server Control? • Runat="server" • Event procedures run on the server • View state saved • Properties and methods are available in server-side event procedures <asp:Button id="Button1" runat="server" Text="Submit"/> private void btn_Click(object sender, System.EventArgs e) { lblName.Text = txtName.Text; } IT Scientific Society - December 2006

  26. Types of Server Controls • HTML server controls • Based on HTML elements • Exist within the System.Web.UI.HtmlControls namespace • Web server controls • Exist within theSystem.Web.UI.WebControls namespace • HTML that is generated by the control <input type="text" id="txtName" runat="server" /> <asp:TextBox id="TextBox1" runat="server">Text_to_Display </asp:TextBox> <input name="TextBox1" type="text" value="Text_to_Display" Id="TextBox1"/> IT Scientific Society - December 2006

  27. Maintaining the State of ASP.NET Server Controls • Server control state is stored in __VIEWSTATE, a hidden control on the Web Form • __VIEWSTATE stores state in a string value of name-value pairs <form id="Form1" method="post" runat="server"> <input type="hidden" name="__VIEWSTATE" value="dDw3NzE0MTExODQ7Oz4=" /> 'HTML here </form> • On by default, adjustable at Web Form and control level <%@ Page EnableViewState="False" %> <asp:ListBox id="ListName" EnableViewState="true" runat="server"> </asp:ListBox> IT Scientific Society - December 2006

  28. Demonstration: Using Server Controls to a Web Form • Using HTML server controls • Displaying browser-specific HTML IT Scientific Society - December 2006

  29. Adding Event Procedures IT Scientific Society - December 2006

  30. How to Implement Code • Three methods for adding code: • Put code in the same file as content (mixed) • Put code in a separate <SCRIPT> section of the content file (inline code) • Put code in a separate file (code-behind pages) • Code-behind pages are the Visual Studio .NET default Code-Behind Page Single file Separate files code <tags> code <tags> Form1.aspx.vb or Form1.aspx.cs Form1.aspx Form1.aspx IT Scientific Society - December 2006

  31. Page1.aspx.cs namespace Project { public class WebForm1 : System.Web.UI.Page { }} Page1.aspx <% @ Page Language="C#"Inherits="Project.WebForm1" Codebehind="Page1.aspx.cs" Src = "Page1.aspx.cs" %> Understanding How Code-Behind Pages Work • Create separate files for user interface and interface logic • Use @ Page directive to link the two files IT Scientific Society - December 2006

  32. What are Event Procedures? • Action in response to a user’s interaction with the controls on the page IT Scientific Society - December 2006

  33. Demonstration: Using Events • Open an ASP.NET page with controls and client-side and server-side event procedures • Click on the controls to view client-side and server-side events running • In the browser, view the source of the page • In the editor, view the event procedure code IT Scientific Society - December 2006

  34. Client-Side Event Procedures • Typically used only with HTML controls • Interpreted by the browser and run on the client • Do not have access to server resources • Use <SCRIPT language="language"> .HTM Pages Internet IT Scientific Society - December 2006

  35. Server-Side Event Procedures • Used with both Web and HTML server controls • Code is compiled and run on the server • Have access to server resources • Use <SCRIPT language="language" runat="server"> .ASPX Pages Internet IT Scientific Society - December 2006

  36. Creating Event Procedures • Visual Studio .NET declares variables and creates an event procedure template in the code-behind page protected System.Web.UI.WebControls.Button btn; private void InitializeComponent() { this.btn.Click += new System.EventHandler(this.btn_Click); } private void btn_Click(object sender, System.EventArgs e) { } IT Scientific Society - December 2006

  37. Page_Init Page_Load Server control events Page_Unload Events in the Web Page Generation Process • Events in the Web page generation process • ASP.NET server control events are handled when the Web page is posted back to the server • Use the Page.IsPostback property to determine if the Web page is being generated for the first time private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // executes only on initial page load } //this code executes on every request } IT Scientific Society - December 2006

  38. Multimedia IT Scientific Society - December 2006

  39. Validating User Input IT Scientific Society - December 2006

  40. What Is Input Validation? • Verifies that a control value is correctly entered by the user • Blocks the processing of a page until all controls are valid • Avoids spoofing or the addition of malicious code IT Scientific Society - December 2006

  41. Client-Side and Server-Side Validation User Enters Data • ASP.NET can create both client-side and server-side validation • Client-side validation • Dependent on browser version • Instant feedback • Reduces postback cycles • Server-side validation • Repeats all client-side validation • Can validate against stored data Error Message Valid? No Client Yes Server Valid? No Yes Web FormProcessed IT Scientific Society - December 2006

  42. Adding Validation Controls to a Web Form • Add a validation control • Select the input control to validate • Set validation properties <asp:TextBox id="txtName" runat="server" /> <asp:Type_of_Validator id="Validator_id" runat="server" ControlToValidate="txtName" ErrorMessage="Message_for_error_summary" Display="static|dynamic|none" Text="Text_to_display_by_input_control"> </asp:Type_of_Validator> IT Scientific Society - December 2006

  43. Combining Validation Controls • Can have multiple validation controls on a single input control • Only the RequiredFieldValidator checks empty controls IT Scientific Society - December 2006

  44. ASP.NET Control Gallery http://www.asp.net • Lots of ISV-written controls are available • Extensibility is a feature IT Scientific Society - December 2006

More Related