Overview of the .NET Framework - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Overview of the .NET Framework

Description:

ASP documents could have embedded scripts in either Jscript or VB -- both purely ... Code can be embedded in ASP.NET documents, or can be separate in a code ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 33
Provided by: richard906
Category:

less

Transcript and Presenter's Notes

Title: Overview of the .NET Framework


1
Overview of the .NET Framework
  • A component is an encapsulation of software that
    can stand by itself and be used by other
    components
  • .NET is based in in part its predecessor, COM
  • .NET Framework is a collection of technologies
    for the development and deployment of .NET
    software systems

2
.NET Features
  • The .NET Common Language Runtime (CLR)
  • Assembly integrity checking using a hash code
  • JIT compilation
  • Garbage collection
  • Exception handling
  • .NET languages from Microsoft
  • VB .NET
  • Managed C .NET
  • JScript .NET
  • J .NET
  • C
  • Many more from other sources, including
    COBOL, Fortran, Perl, and Python

3
JIT Compiler
  • Every .NET language has a compiler that produces
    IL, which is JIT compiled to machine code
  • There is no IL interpreter

4
.NET Features (2)
  • Common Type System (CTS)
  • Minimum type set supported by all .NET languages,
    e.g., Int32, which corresponds to int in C
  • All CTS types are derived from System.object
  • Two categories of data types value and reference
  • Minimum language constructs and rules, e.g., no
    operator overloading, no pointers, identifiers
    are not case sensitive

5
.NET Features (3)
  • Framework Class Libraries (FCL) gt 4000 classes
  • Aim of CLI and CLR interoperability -- a
    component in any .NET language can
  • Inherit from any other .NET language class
  • Call the methods of any other .NET language class
  • Subclass any class from any .NET language

6
C Heritage
  • From Java
  • Single inheritance
  • Interfaces
  • Garbage collection
  • No global types or variables
  • Level of coercion
  • From C
  • Pointers
  • Operator overloading
  • Preprocessor
  • structs, enums,
  • From Delphi and VB
  • Properties
  • From J (actually, J)
  • Delegates

7
C New Features
  • Indexes
  • Attributes
  • Events
  • A safer switch statement
  • A new kind of struct

8
C Primitive Types and Expressions
  • Similar to Java, except C has unsigned integers,
    a 16-byte decimal type, and pointers

9
C Data Structures
  • Similar to Java and C
  • class library support for Array, ArrayList,
    Queue, and Stack
  • Array class has many methods and a Length
    property
  • An enumeration type, similar to that of C,
    except no coercions to or from other types

10
C Control Statements
  • Like Java, except
  • There is a goto
  • There is a foreach statement
  • The switch has a static semantics rule that
    requires each selectable segment to end in an
    unconditional transfer (either break or goto)

11
C Classes, Methods, and Structures
  • Like Java, except
  • Parameters can be passed by value (default),
    passed by reference (ref), or passed by result
    (out)
  • A method that can be overriden must be marked
    virtualA method that overrides must be marked
    overrideA method that has the same protocol as
    an inherited method but is NOT to override it is
    marked new
  • A method can take a variable number of
    parameters, if they are the same type

12
C struct
  • Lightweight class
  • Supports constructors and can implement
    interfaces
  • Does not support inheritance or subclasses
  • Is allocated from the stack

13
C Properties
  • Special data field of a class that can provide
    implicitly called get and set accessors
    public class Weather public int DegreeDays
    get return degreeDays
    set degreeDays value
    private int degreeDays // end
    of property DegreeDays ... // end of
    class Weather ... Weather w new
    Weather() .. w.DegreeDays degreeDaysToday

14
Delegates
  • object-oriented method pointerspublic delegate
    void AHandler (object o, System.EventArgs
    e)AHandler can reference any method with this
    protocol

15
Program Structure
  • System is a namespace of FCL that provides input
    output, string manipulation, threading, and
    collections
  • Abbreviations of elements of System are permitted
    by using System

16
File Storage for Programs
  • A file can store any number of public classes
    and/or interfaces
  • Every class can define a Main method, but if
    there are more than one in a file, you must tell
    the system where to begin

17
ASP.NET
  • Based on ASP, but revolutionarily different
  • ASP documents could have embedded scripts in
    either Jscript or VB -- both purely interpreted
  • Inefficient
  • Mixing script and markup is confusing
  • Scripting languages are unreliable
  • ASP.NET differs from JSP in two ways
  • Any .NET language can be used
  • All ASP.NET code is compiled

18
ASP.NET
  • Code can be embedded in ASP.NET documents, or can
    be separate in a code-behind file
  • Every ASP.NET document is compiled into a class
  • Base class is System.Web.UI.Page, unless there is
    a code-behind class (then it is the base)

19
ASP.NET document components
  • XHTML markup
  • Directives appear in lt gt blocks
  • example, Page, with attribute Language
  • Render blocks lt gt
  • No method definitions
  • Put into a function in the document class
  • Declaration blocks
  • Script elements - method definitions
  • Server-side comments lt-- --gt

20
Code-behind Files
  • The _at_Page directive must specify the code-behind
    file in a Inherits attribute
  • If you want the code-behind file implicitly
    compiled, include a CodeFile attribute
  • ex2.aspx and ex2.aspx.cs

21
ASP.NET Controls
  • Two collections of server controls HTML controls
    and Web controls
  • HTML Controls
  • One-to-one correspondence with the XHTML
    elements,e.g., HtmlInputButton - ltinput type
    ?submit? /gt
  • Difference between XHTML elements and their
    corresponding HTML controls is that server-side
    code can interact with HTML controls
  • Many can raise events, e.g., ServerClick and
    ServerChange (see Table 13.1, page 540)
  • All HTML controls are converted to objects in the
    corresponding document class

22
ASP.NET Controls (2)
  • Any element that will be used by server-side code
    must include the runat "server" attribute
  • A form that has server-side elements must also
    include the runat "server" attribute
  • ltform runat ?server?gt ltinput type
    ?text? id ?address? runat
    ?server? /gt lt/formgt
  • The form has no action attribute
  • The server-side code (the document class) would
    have protected HtmlInputText address

23
ASP.NET Document With a Form
  • Two purposes
  • Describe the form to be displayed by the browser
  • Process the form when its data is submitted
  • Each of these has its own kind of request
    initial and postback
  • Document classes maintain form data state between
    postbacks in the ViewState hidden element of the
    form
  • ex3.aspx

24
The Life of an ASP.NET Document
  • The client requests the document
  • A document class is created by compiling the
    requested document its constructor is called
  • The control state of the document is initialized
    with ViewState
  • Request form data is used to set the control
    state
  • The current control state is saved in ViewState
  • The instance is executed and the results are
    returned to the client
  • Class and its instance are deleted on the server

25
Life (2)
  • The client causes a postback
  • A document class is compiled and its constructor
    is called
  • The client interacts with the form
  • The control state is initialized from ViewState
  • The control state is set with the form data
  • The current state is saved in ViewState
  • The instance is executed and the results are
    returned to the client

26
Page-Level Events
  • Implicitly raised during the process of
    processing a request
  • Load
  • Unload
  • PreRender
  • Init
  • To Write And Register Event Handlers
  • Write handlers with preassigned names and a
    specific protocol
  • implicitly registered
  • Called auto event wireup
  • public void Page_Init(System.EventArgs e)
  • or overload virtual methods and manually register
    them

27
Control Events
  • ServerClick and ServerChange
  • Ways to write and register handlers
  • 1. Write them as functions and register them in
    the XHTML (OnServerClick and OnServerChange)prot
    ected void TextBoxHandler (object src,
    System.EventArgs e) ... ltinput type
    ?text? id ?Name? OnServerChange
    ?TextBoxHandler? runat ?server? /gt
  • 2. use the standard CLR approach
  • Write the handler, as before
  • Create a handler delegate instance, passing the
    name of the handler to the constructor
  • Subscribe the new delegate instance to the
    control and the event name
  • protected void Page_Init(object src,
    EventArgs e) Name.ServerChange new
    EventHandler(TextboxHandler)

28
Revised list of what happens
  • Client requests the document
  • A document class is compiled and its constructor
    is called
  • The Page event Init is raised
  • The control state of the instance is initialized
    with ViewState
  • The form data is used to initialize the control
    state
  • The Page event Load is raised

29
Revised list (2)
  • Server-side control events are raised
  • The Page event PreRender is raised
  • The current control state of the instance is
    saved in ViewState
  • The instance is executed and the results returned
    to the client
  • The Page event Unload is raised
  • The class and its instance are deleted on the
    server

30
Web Controls
  • Larger and richer collection than the HTML
    controls based on those of VB (page 547)
  • Weaker connection to the XHTML element
  • More consistent programming interface
  • Web controls include
  • Panel allows collections of elements to be
    handled together
  • AdRotator Easy way to have different content
    appear on different requests
  • Validator

31
Web Control Creation
  • Controls can be created by either markup or by
    programming code, for example,
  • ltasp.button id ?helpButton? Text
    ?help? OnClick ?OnClickHandler?
    runat ?server? /gt protected
    Button helpButton new Button()
    helpButton.Text ?help? helpButton.id
    ?helpButton? helpButton.OnClick
    ?OnClickHandler? helpButton.runat ?server?
  • Control placement is awkward
  • ex4.aspx and ex4.aspx.cs

32
Validation Controls
  • Commonly used
  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpressionValidator
  • Validation controls are placed just after the
    controls whose values they are to validate
  • ControlToValidate attribute specifies the control
    to be validated
  • ErrorMessage attribute specifies the error
    messageex5.aspx
Write a Comment
User Comments (0)
About PowerShow.com