Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 381 Day 26. Agenda  Capstone projects are DUE May 10 at 1PM  I will be covering ASP.NET from the handouts  There will be one lecture on Database.

Similar presentations


Presentation on theme: "COS 381 Day 26. Agenda  Capstone projects are DUE May 10 at 1PM  I will be covering ASP.NET from the handouts  There will be one lecture on Database."— Presentation transcript:

1 COS 381 Day 26

2 Agenda  Capstone projects are DUE May 10 at 1PM  I will be covering ASP.NET from the handouts  There will be one lecture on Database access  Quiz 4 on May 4 ASP.NET and Database Access  Assignment 7 (final one) is posted and is Due on May 3 at Midnight Create a complex ASP.NET page http://perleybrook.umfk.maine.edu/samples/a ssign7/UMFKorder.aspx http://perleybrook.umfk.maine.edu/samples/a ssign7/UMFKorder.aspx

3 ASP.NET  Where ASP used interpreted languages ASP.NET uses complied languages ASP example (code) ASP example(code) Same in ASP.NET (code) Same in ASP.NET(code)  ASP.NET uses many languages We will use C# Another example (code) Another example(code)

4 NEW Features of ASP.NET  The following are not part of ASP or any other traditional Web programming languages Server Controls Validation Controls List Controls and Rich Controls HTML Server Controls User and Custom Controls Web Services Integration

5 Server Controls  Programmable; prepackaged server code program code written to perform dynamic functions Converted to HTML by server Look the same as standard from elements but can be dynamically control by server side code at run-time  Example server controls (code) Example server controls(code)

6 Validation Controls  Used to validate data users enter into from elements Make a field required Compare against range of inputs Compare two values  Validation controls process data BEFORE a form is submitted

7 List Controls and Rich Controls  List controls are used to iterate, process and display dynamic data Database query Program array  Rich controls are complex components Calendar Ad Rotator

8 HTML Server Controls  Same as HTML elements except runat=“server”  Example (code) Example(code)

9 User and Custom Controls  User Controls Mini-ASP.NET pages Included in other ASP.NET pages  Custom Controls Written entirely in another language like  C++, C# VB Precompiled and added to ASP.NET

10 Web Service Integration  Small Programs to which you can call functions and get results  Transfer data using XML over HTTP  AN Example US Postal Service has web service to output all ZIP Codes In order to include ZIP Codes in your ASP.NET application you simply poll the USPS Web Service

11 Web Service HTTP Response HTTP Request Client PC Webserver SOAP- Capable Browser Web Service -- Interface Properties Methods SOAP Message Using XML Syntax Web Service

12 Similarities to ASP  ASP pages coexist with ASP.NET Cannot share session information  Still have Response and Request objects All info requested with a web page  Form data  Query Strings All info returned with a webpage

13 Components of.NET  3 major parts Common language runtime (CLR)  A virtual machine that runs all.NET programs  Run-time language is Microsoft Intermediate language (MSIL)  Uses JIT Compilation Common type system (CTS)  Standard set of types Value types (int, char…) Reference types for objects  Common naming convention (CLS) Class Library  Predefined code packaged as classes  All.NET classes or part of System namespace

14 Class Libraries  Namespaces Hierarchical naming convention Matches class inheritance tree  Common Namespaces in.NET System root namspace System.data System.xml System.net System.security System.web

15 Writing C# code in.NET  Object oriented Class  public class Car { } Object  Car c = new Car(): Member variable  private int Gas; Method  private void Drive() {} Property  Public int Gasoline { get {return Gas; } set {Gas=value;}} Overloading  Method with different parameter list Inheritance  The power of OOP

16 Getting Started with.NET  Installing.NET Need.NET SDK  Loaded with Visual Studio.NET  Available under MSDNAA Need IIS  Personal edition or Server Microsoft Data Access Components (MDAC)  For data base access Service packs and updates

17 .NET Framework SDK  Assemblies ASP.NET pages Executed in CLR  Metadata Data about data Provides location of class definitions. How to load classes and any defines attributes  Global Assembly Cache Centralized locations for assemblies

18 Working with Dreamweaver  Chapter 3 of text provides a good overview Only issue is that it assumes that you have a web server available on your Desktop..we do in N-105. You may not have on your home computer

19 Setting up Dreamweaver MX to Create ASP.NET Applications  Open Dreamweaver MX.  Select Site > New Site… from the Menu bar to create a new site.  On the Basic tab, enter the following information, clicking Next at the bottom of each screen: Name: MyASPNET Yes, I want to use a server technology.  Select ASP.NET C# as the server technology. Edit and then upload to remote testing server, storing your files at H:\asp. URL to browse to the root of your site http://perleybrook.umfk.maine.edu/classes/cos381/”last name”. No, do not copy files when I am done editing.  Click Done to create an initial cache of your site.  Lets do this “Step by Step”

20

21

22

23

24

25

26 Web Form Controls  Learn by doing Create new ASP.NET C# page

27 Insert new Form Element

28 Set to Run at Server

29 Add Label Control

30 Web Form  Save and test previous example  Go to “View Source”

31 Building Dynamic Pages  Update page based on external conditions  runat=“server” means that a control can be manipulated  Let’s modify our page to display an user input ADD asp:textbox ADD asp:button

32

33 Then we add a Page Load Function Change Function text

34 About Post Back  Form “post’ back to themselves No need to reload form Makes the form interactive  isPostBack is true when Something control has caused the form to be to be sent to the server and the form is “reloaded”  Problem is that you allways return to the same form page

35 Form vs Query Srting  In CGI programming we used the Query String to collect data from a form and pass it to our script Uses method=“get” Security/performance issue  In ASP.Net We use the action=“post” and read our values from the response object  Response.Form[“txtFirstName”] We use get when we want to load a different page and pass data to the page  stuff

36 Using Request.Form Add Text

37 Examples ASP.NET  All examples from class are at http://perleybrook.umfk.maine.edu/samples/A SPdotNet/script.htm http://perleybrook.umfk.maine.edu/samples/A SPdotNet/script.htm  Today’s Example (so far) WebForm1 (code) WebForm1(code)

38 Moving between pages  Since Web Form Post Back ….how do you go to another web Page? Response.Redirect(“Url”);  If you don’t want to finish processing the page you are on Response.Redirect(“Url”, true);  The hidden form element __VIEWSTATE gets lost

39 Session Variables  To move data between different Web forms you can use Session Variables To Set a Session Variable (original Web Form  Session[“aVariable”] = “some data”; To get a Session Variable (second Web Form)  lblSomeLable.Text = Session[“aVariable”].ToString();  String str = Session[“aVariable”].ToString(); Example (code1) (Code2) Example (code1) (Code2)

40 Working With Drop-Down Lists  To add a Drop Down use Dreamweaver’s wizard

41 Drop Down List  Coding Drop Downs In Body section List Item 1 To add a item dynamically dblSampleList.Items.Add("List Item 2"); dblSampleList.Items.Add("List Item 3"); Example (code) Example(code)

42 Binding Data  Used for binding data from a Database or an array to a controls at run time Another way to add list items Bind values to variables  Two Styles for Binding Data exist  Textbook Error References to BindData() should be change to DataBind()

43 Binding Data  First Style  In body of HTML  Type in or use ASP.NET Bound Data Icon in Dreamweaver  Must call Page.DataBind(); in Page_load function (note error in text book!)  Will be replaced by value of variable  Second Style

44 Binding Data  Second Style In Page_Load Function  someList.DataSource = someList;  Page.DataBind();  Example (code) Example (code)

45 Event Handling in ASP.NET  Events are messages sent out by objects Different objects – Different messages  In ASP.NET events occur when the server detects an event page-Level events  Occur when users visits a web page Control events  Occur when a user manipulates an ASP.NET control

46 Page Events  Web Form trigger 11 events when loaded (in order) 1. Initialization (Page_Init) 2. Load View State 3. Post Back Data Processing 4. Page Load (Page_Load) 5. Post Back Change Notification 6. Post Back Event Processing 7. Pre-rendering (Page_PreRender) 8. Same view State 9. Rendering 10. Disposing 11. Unload

47 Page Level Events  These events do not need to be registered  Most common Used Page Event is Page_Load protected void Page_Load(Object Src, EventArgs E) { if (!PostBack) DataBind(); }  Example (code) Example(code)

48 Control Events  Must have registered Handlers Use Delegates which listen for events and then delegating responsibility for the event to the assigned handler Generally event handlers (like Page_Load) have two parameters  Object src The object which created the event  EventArgs E Specific information about the event

49 Creating a handler for a ASP.NET Control  ASP.NET Control must be in a Web Form that is set to runat=‘server”  Use Dreamweaver Wizard

50 Control Events  The Dreamweaver wizard will register the event but you still need to write the handler code Between tags in Head void btnTest_OnClick( Object Src, EventsArgs E) { Some C# code } ExampleExample (Code)(Code)

51 Adding Controls and Events Programmatically  Between tags in head Button btnTest = new Button(); btnTest.Text = “daButton”; btnTest.Click += new EventHandler(this.btnTest_OnClick); samePanel.Controls.Add(“btnTest”); Make sure you write the btnTest_Onclick functions  Example (code) Example(code)

52 Complex Controls  Have lots of functionality; sometimes called rich controls  We will look at two complex controls Ad Rotator File upload  You can create your own Complex Controls (chap 10 & 11 in text)

53 AD Rotator  Places Different images in your Web Form every time someone loads the page. Images are licked to a web site 3 Parts  Images  The ASP.NET Ad Rotator Control  A XML configuration file Example (Code) Example(Code)

54 XML config File  *.jpg URL text 50 Macromedia *.jpg UrL Text 30 Microsoft example

55 Adding The Ad Rotator Control  Use Dreamweaver wizard More tags icon Under ASP.NET tags use asp:adrotatoor

56 Web Form Validation  Input fields need to be checked Check for errors before using the data in a program or putting into a database We can check for  Existence  Format  Range of vales  Data type  ASP.NET includes validation controls that automatically provide form field validation with little or no extra coding

57 Preprogrammed Validators  Does both client side and server side validation of data DHTML  CSS  JavaScript  ASP.NET includes 5 preprogrammed Validators Required field Range Compare Regular expression Custom

58 Adding a Required field validator  Must use a Web Form that runat=‘server”

59 Adding a Validation summary  This is a place for all the validation errors to appear ExampleExample (code)(code)

60 Value Based Validators  Required Text Validators only require that some text is entered but you may want to check to actual text entered Compare against  Value (compare validator)  Type (compare validator)  Another control (compare validator)  A regular expression (regular expression validator)  A range of values (range validator)  Other conditions (custom validator)

61 Adding value Validators

62 Regular Expression  Same as JavaScript and Perl \w is alpha char \d is decimal char * zero or more + one or more ? Zero or one. Matches any character except newline [] range of characters [A-Z] upper case \* matches * \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)  Matches e-mails

63 Validations examples  Compare, Range & Regular expression Example (code) Example(code)  Custom validator Example (code) Example(code)  Assignment #7 http://perleybrook.umfk.maine.edu/samples/assign7/UMFKorder.aspx


Download ppt "COS 381 Day 26. Agenda  Capstone projects are DUE May 10 at 1PM  I will be covering ASP.NET from the handouts  There will be one lecture on Database."

Similar presentations


Ads by Google