190 likes | 363 Views
ASP.NET. Another “brief” Overview. ASP.NET. Increasingly the Web and the browser interface are used to support application development. ASP.NET is not a CLR-based language. ASP.NET is part of the class library
E N D
ASP.NET Another “brief” Overview
ASP.NET • Increasingly the Web and the browser interface are used to support application development. • ASP.NET is not a CLR-based language. • ASP.NET is part of the class library • In “classic” ASP, VBscript was the default language for developing ASP pages (part of the reason so much VB is out there.... • VBscript is not part of the framework. • ASP.NET applications are written in a CLR-based language (e.g., VB or c#)
code-behind Default.aspx.cs Default.aspx Compiled Into MSIL IIS Browser Default.aspx http Web Controls ADO.NET txtLogin Validate person txtPwd Person.cs cmdLogin dbms Common Language Runtime
aspx pages • ASP.Net is not a scripted environment like classic ASP. All pages are compiled into classes that run on the CLR. • The “output” of an aspx is HTML 4.0 which is sent to the requesting browser via the web server.
aspx pages • In classic ASP, each page is processed sequentially and interpreted rather than compiled. • There was really only one “event” in this model: “page was requested.” • ASP.Net is a fully event-driven environment.
aspx pages • Classic ASP versus ASP.Net • SQL Injection example • ASPX page life cycle • Critical understanding for programming controls
ASPX page life cycle • http://msdn2.microsoft.com/en-us/library/ms178472.aspx http://www.4guysfromrolla.com/images/pageLifeCycle.gif
PostBack • IsPostBack • Property that indicates whether page is loaded for first time or the result of a user gesture // Placed in the Page_load event // C# if (!IsPostBack) { SetFormMode(); } // Vb.Net If Not IsPostBack Then SetFormMode() End If
Web Controls • Web controls are an alternative to HTML controls. • An aspx page can have both
Web Controls HTML Controls You can tell if it is a web or HTML control because web controls have a little green arrow in the corner.
Code-behind • Mixing markup tags and presentation logic syntax makes a page very difficult to read and maintain. • Code-behind separates the markup tags from code in a separate file. • The aspx and aspx.vb files are linked by a reference.
Code-behind • The code in a code-behind page could be written inline with script blocks • <script runat=“server”></script> • Or render blocks • <% %> • For example, in main.aspx (previous version of SQL Exercise System) I use a render block to print the content of the treeview.
I use the Write method of the Response object to print the contents of the variable I populated in the code-behind page in the page_load event.
This treeview is generated dynamically from the database and then rendered by Response.Write method.
Code-behind • Although you can still write code directly in the aspx page, code-behind means: • Clean separation of HTML and code • Easier Reuse • Simpler Maintenance • Deployment without source code