BMIS 289: Spring 2002 Gonzaga University - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

BMIS 289: Spring 2002 Gonzaga University

Description:

Note a couple of things required for the code in the OnClick event handler to function. ... In our OnClick event handler it would be handy to know if all the ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 33
Provided by: colin83
Category:

less

Transcript and Presenter's Notes

Title: BMIS 289: Spring 2002 Gonzaga University


1
BMIS 289 Spring 2002Gonzaga University
  • Class 14
  • ASP.Net

2
Tonights Agenda
  • Evaluations
  • ASP.Net
  • Final Projects

3
ASP.Net
  • ASP.Net is the latest version of the ASP web
    programming technology.
  • Microsoft defines ASP.Net as
  • A programming framework built on the common
    language runtime that can be used on a server to
    build powerful Web applications
  • So what exactly does that mean? To understand it
    better we need to clarify what the Common
    Language Runtime is.

4
What is .Net?
  • A couple years ago, Microsoft began introducing
    what it calls .Net (DotNet)
  • DotNet is an environment for creating and running
    computer programs, including web applications.
  • It consists of two major components
  • Common Language Runtime (CLR)
  • .Net Framework Class Library (NFCL)

5
CLR
  • The CLR is the core engine of DotNet. Without it,
    DotNet would not function.
  • The CLR is an environment (an agent) in which
    code executes. Microsoft has designed this
    environment with these things in mind
  • Memory Management - Security
  • Thread Management Safety - Interoperability
  • Remoting - Robustness
  • Type Safety - Versioning

6
NFCL
  • The .Net Framework Class Library is a collection
    of object-oriented code libraries that can be
    used to create many different types of
    applications
  • Command line Applications
  • GUI Applications
  • Web Applications
  • Server/System Applications
  • The NFCL saves you from writing a lot of the
    plumbing code that goes along with applications
    like these and makes it easier to focus on the
    logic of your application.

7
Benefits of .Net
  • As we mentioned already, it takes care of a lot
    of the dirty work associated with writing
    modern Windows programs.
  • Example memory management is handled
    automatically.
  • Supports a wide variety of languages
  • The most popular DotNet languages are VB.Net and
    C, but other languages like C are also
    supported.
  • It is not interpreted, like Java.
  • It is designed to allow it to run on platforms
    other than Microsoft Windows.
  • Though, as of this presentation, it is primarily
    a Windows technology.

8
Drawbacks of .Net
  • Because you are programming within a framework
    you are constricted (for the most part) by that
    framework.
  • Example it is impossible in many situations to
    use pointers in DotNet code.
  • Support for other platforms is almost
    non-existent at the moment and will take some
    time to develop
  • If it does at all.
  • DotNet does not entirely remove the need to
    develop and maintain program code in non-DotNet
    environments (Un-Managed Code).

9
.Net As A Whole
10
ASP.Net Features
  • Simplicity Power
  • Many common features found in web applications
    are built-in to ASP.Net and easy to use.
  • Since ASP.Net is part of the .Net Framework it
    has access to most of its functionality.
  • Multiple languages can be used to write ASP.Net
    pages (VB.Net, C).
  • Easier and more powerful configuration
    capabilities simplify the process of setting up
    and maintaining a web application.

11
ASP.Net
  • In order for ASP.Net to run on a machine (server)
    it must have the .Net Runtime installed and at
    least IIS 5.0 (gtWindows 2000).
  • The .Net Runtime can be downloaded from Microsoft
    and IIS 5.0 comes with Windows 2000/XP.

12
ASP.Net
Test001.aspx
  • A simple page in ASP.Net would look something
    like this

lt_at_ Page Language"C" gt lthtmlgt ltheadgt lt/headgt ltb
odygt lt int i for(i1 ilt10 i)
Response.Write("This is line number " i
"ltbrgt") gt lt/bodygt lt/htmlgt
13
ASP.Net
  • This code looks a lot like the regular ASP we are
    use to, but there is a difference.
  • We are using the programming language C to write
    the ASP code. The language we are using on this
    page was specified with the _at_ Page Language
    directive.
  • The syntax rules for C are more like C and
    Java.
  • If we wanted to, we could use the VB.Net language
    which is much more like VBScript.

14
ASP.Net
  • One of the most powerful features of ASP.Net
    pages are known as server controls.
  • These are objects that can be embedded within an
    ASP.Net page and referenced programmatically.
  • There are many different types of server controls
    that come with ASP.Net out of the box
  • Simple output labels - Calendars
  • Form inputs - Data Access
  • Moreover, programmers can also create their own
    custom controls.

15
ASP.Net
Test002.aspx
  • Here is a simple page that uses a Label server
    control

lt_at_ Page Language"C" gt lthtmlgt ltheadgt lt/headgt ltb
odygt ltpgt ltaspLabel id"Label1"
runat"server" BackColor"Gray"gt This is
text from a ASP.Net control! lt/aspLabelgt
lt/pgt ltpgt ltstronggtThis is normal HTML
Text!lt/stronggt lt/pgt lt/bodygt lt/htmlgt
16
ASP.Net
Test003.asp
  • Now lets consider the case where we have a form
    on a page that has two fields, a text box and a
    drop down menu.
  • Suppose we wanted to retain the values a user
    entered into the form after it had already been
    posted.
  • A common requirement in real-world forms that do
    a lot of validation.
  • Using traditional ASP techniques we have to
    capture those inputs and write them back into the
    form, manually.

17
ASP.Net
Test003.aspx
  • ASP.Net has server controls that act as form
    inputs.
  • This code has the same functionality as the
    previous ASP code

ltform actiontest003.aspx methodpost
runatservergt Name ltasptextbox id"FullName"
runat"server"/gtltbrgt State
ltaspdropdownlist id"State" runatservergt
ltasplistitemgtWashingtonlt/asplistitemgt
ltasplistitemgtOregonlt/asplistitemgt
ltasplistitemgtIdaholt/asplistitemgt
lt/aspdropdownlistgt ltaspbutton text"Submit"
runat"server"/gt lt/formgt
18
ASP.Net
  • Note that in the previous code we had four server
    controls
  • ltform runatservergt
  • ltasptextbox runatservergt
  • ltaspdropdownlist runatservergt
  • ltaspbutton runatservergt

19
ASP.Net
Test004.aspx
  • Many server controls have events that we can
    write code against which will be executed when
    that event occurs.
  • For example, the button control has an OnClick
    event

ltscript language"C" runatservergt void
SubmitBtn_Click(Object sender, EventArgs e)
Message.Text "lth1gtHi " FullName.Text
", you live in " State.SelectedItem
"lt/h1gt" lt/scriptgt
20
ASP.Net
  • Note a couple of things required for the code in
    the OnClick event handler to function.
  • First, we had to create an additional server
    control a label called Message
  • Then, we had to indicate which function should be
    called when the button was clicked

ltasplabel id"Message" runat"server"/gt
ltaspbutton text"Submit" OnClick"SubmitBtn_Click
" runat"server"/gt
21
ASP.Net
Test005.aspx
  • There are also server controls that can make
    validating form input a much simpler process.
  • For example, we can require that an input be
    entered by dropping in a RequiredFieldValidator
    control

ltaspRequiredFieldValidator ControlToValidate"Ful
lName" Display"Dynamic" errormessage"You
must enter your name!ltbrgt" runatserver/gt
22
ASP.Net
  • The RequiredFieldValidator is capable of using
    client-side script to validate the input on the
    fly.
  • This functionality will only be available on
    browsers that support it.
  • Validation always occurs on the server
    (downlevel)
  • Browsers that support it can perform the
    validation on the client-side and catch potential
    errors quicker (uplevel)
  • If a browser does not support the uplevel
    validation then the downlevel validation will
    still function.

23
ASP.Net
  • If we want, we can manually disable the uplevel
    validation
  • Note that the Display property does not effect
    whether uplevel validation is additionally
    performed.

ltaspRequiredFieldValidator ControlToValidate"Ful
lName" EnableClientScriptFalse
Display"Dynamic" errormessage"You must
enter your name!ltbrgt" runatserver/gt
24
ASP.Net
Test006.aspx
  • In our OnClick event handler it would be handy to
    know if all the validators succeeded.
  • We accomplish this with the Page.IsValid
    property

void SubmitBtn_Click(Object sender, EventArgs e)
if (Page.IsValid) // perform code

25
ASP.Net
Test007.aspx
  • If you want to summarize all form input errors
    after a submit button is clicked you can use the
    ValidationSumary control.
  • This control displays all error messages
    generated by other validation controls on the
    page.

ltaspValidationSummary HeaderText"You must enter
a value in the following fields" DisplayMode"Bul
letList" EnableClientScript"true" runat"server"/
gt
26
ASP.Net
  • DotNet also encompasses a version of ADO known as
    ADO.Net
  • ADO.Net is an object model, like the traditional
    ADO, that interfaces with many different
    providers.
  • The object model looks something like this

27
ASP.Net
  • The process of accessing and manipulating data
    via ADO.Net works roughly like this
  • A Connection object is created to link the
    ASP.Net page to the database.
  • A Command object is created to issue a command to
    the database (SQL, Stored Procedure, etc).
  • If all you want to do is display data then the
    results can be read into a DataReader object for
    fast, efficient display.
  • If you need to process the data further the
    results are read in to a DataSet object which is
    accessed via the DataAdapter objects.

28
ASP.Net
Test008.aspx
  • The code in this example performs all the
    essential steps for reading from an Access
    database.
  • We use the OLEDB connection, command, and reader
    objects to perform our operations.

29
ASP.Net
Test009.aspx
  • If you want to display records from a database in
    an HTML table then ASP.Net provides the DataGrid
    server control which generates all the HTML
    automatically.
  • Note the use of the Page_Load function in this
    code. That function is an event handler that is
    automatically called each time the page is loaded.

30
ASP Resources
  • LearnASP.com
  • www.learnasp.com
  • Good for finding small, concise lessons.
  • ASP 101
  • www.asp101.com
  • Many beginner and advanced topics here. Articles
    are larger than LearnASP
  • 4 Guys..
  • www.4guysfromrolla.com
  • A huge ASP resource.
  • MSDN
  • msdn.microsoft.com
  • Microsoft programming resources.

31
Contact
  • Yes, I stand behind what I teach so if you have
    any questions or problems in the future then just
    fire me an email
  • colin_at_colinfukai.com

32
THE END
Write a Comment
User Comments (0)
About PowerShow.com