Documente Academic
Documente Profesional
Documente Cultură
Rishi Kothari
Agenda
Overview of .NET Overview of ASP.NET Creating an ASP.NET Web Form Adding Event Procedures
Overview of .NET
Developer Tools
Clients
Databases
.NET Framework
User Experiences
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
XML Web Services User Interface ASP.NET ADO.NET and XML .NET Framework Class Library Common Language Runtime
Message Queuing COM+ (Transactions, Partitions, Object Pooling) IIS WMI
Win32
One runtime for all . NET-Based Languages Manages threads and memory
Garbage collection
Multiple versions of a DLL can run simultaneously Applications can specify a version of a DLL to use
The class library is a set of classes (properties and methods) that all .NET applications can use
Choosing a Language
Development experience
Browser compatibility
Overview of ASP.NET
ASP Page
(.asp)
Graphic Files
ADO
COM Objects
COM+ Services
Data Tier
Data Source
Web Form
(.aspx)
Code-Behind File (.aspx.vb or .aspx.cs) Graphic Files
User Controls (.ascx) Business Logic Tier Proxy XML Web Services (.asmx) Data Tier
RCW
Page directives
Language
Structural changes
All
functions and variables must be declared within a <script> block one language per page Functions are no longer supported; use Response.Write with Web controls
Only
Render
JIT compiler
MSIL
Native code
Create a Web application Add controls to a Web Form View the HTML generated Add an event procedure
.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>
Runat="server"
Exist within the System.Web.UI.WebControls namespace HTML that is generated by the control
Server control state is stored in __VIEWSTATE, a hidden control on the Web Form
<form id="Form1" method="post" runat="server"> <input type="hidden" name="__VIEWSTATE" value="dDw3NzE0MTExODQ7Oz4=" /> 'HTML here </form>
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)
Separate files
Code-Behind Page
code
<tags>
<tags>
Form1.aspx Form1.aspx
code
Form1.aspx.vb or Form1.aspx.cs
Create separate files for user interface and interface logic Use @ Page directive to link the two files 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" %>
Open an ASP.NET page with controls and client-side and server-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">
Internet
.HTM Pages
Internet
.ASPX Pages
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) { }
Page_Init
Page_Unload
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 }
Multimedia
Client-side validation
Error Message No
Dependent on browser version Instant feedback Reduces postback cycles Repeats all client-side validation Can validate against stored data
Server-side validation
Valid?
Yes
No
Purpose Require user input Compare to another control, a value, or a data type RangeValidator Compare to a range CustomValidator Compare to a custom formula RegularExpressionValidator Compare to a regular expression pattern ValidationSummary Summarize the state of the validation controls on a page
Create an ASP.NET Web Form with TextBox and Button controls Add a RequiredFieldValidator control Add a RangeValidator control Add a RegularExpressionValidator control Add a ValidationSummary control
Thanks!