Introduction to ASP.NET, Second Edition2 Chapter Objectives.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Introducing JavaScript
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
The Web Warrior Guide to Web Design Technologies
VBA Modules, Functions, Variables, and Constants
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Basics of ASP.NET. 2 © UW Business School, University of Washington 2004 Outline Installing ASP.NET and Web Matrix Data Types Branching Structure Procedures.
Using VB.NET with ASP.NET Page. Chapter Objectives.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Using Visual Basic.NET in Web Pages ASP.NET. Object-Oriented Programming (Page 1) Classes and Objects – Create objects based upon a class An object is.
JavaScript, Fourth Edition
Chapter 2: Introduction to C++.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
ASP.NET Programming with C# and SQL Server First Edition
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 51 Using Visual Basic.NET within an ASP.NET Page Introduction to ASP.NET By Kathleen Kalata.
Chapter 8 Cookies And Security JavaScript, Third Edition.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Using Client-Side Scripts to Enhance Web Applications 1.
Chapter 2: Using Data.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Applications Development
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Copyright Curt Hill Variables What are they? Why do we need them?
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Fourth Edition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
Programming with Microsoft Visual Basic th Edition
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
A variable is a name for a value stored in memory.
Chapter 6 JavaScript: Introduction to Scripting
Java Primer 1: Types, Classes and Operators
Programming the Web Using Visual Studio .NET
Introduction to Scripting
JavaScript: Functions.
JavaScript.
Variables and Arithmetic Operations
WEB PROGRAMMING JavaScript.
PHP.
Chapter 2: Introduction to C++.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Introduction to ASP.NET, Second Edition2 Chapter Objectives

Introduction to ASP.NET, Second Edition3 Object-Oriented Programming Programming statements, or code, combined into logical groupings, functions, event handlers, and procedures

Introduction to ASP.NET, Second Edition4 Object-Oriented Programming (continued) Objects and Classes – create objects based upon a class An object is a set of related code that is compartmentalized and built upon these classes access the object across multiple Web pages – Create an object the object definition, called the class creating an instance of the class – use the class as the template for creating the new object

Introduction to ASP.NET, Second Edition5 Object-Oriented Programming (continued) Instantiation – Declaring and initializing an object from a class – You create objects from the same definition Public Class TaraStoreClass Private StoreName As String = "Tara Store" End Class

Introduction to ASP.NET, Second Edition6 Object-Oriented Programming (continued) Restrict applications access to the class – Public - interact with other objects outside of the base class – Private - called only from within the base class – Protected - called from within the base class, and within subclasses – Subclass – a class that inherits from a base class – Friend - called anywhere from within the same application

Introduction to ASP.NET, Second Edition7 Object-Oriented Programming (continued) Instantiate an object based on the class definition – Declare a variable keyword Dim - to store the object keyword New - to identify that this is an object based on a class definition Dim Ch5Class As New Chapter5.TaraStoreClass()

Introduction to ASP.NET, Second Edition8 Object-Oriented Programming (continued) Decision control structures - organize the order in which the code is executed Event handlers - execute when the event occurs Procedures - named grouping of one or more programming statements – Parameters - values passed; multiple values are separated in a comma delimited list within parentheses Functions - named grouping of programming statements that can return a value

Introduction to ASP.NET, Second Edition9 Object-Oriented Programming (continued) Properties – Set the value of a variable defined within an object – Identified by the object name, a period, and the name – Assigned a default value within the object definition, or the value is set as “undefined” – All new objects inherit the same properties as the original object definition

Introduction to ASP.NET, Second Edition10 Object-Oriented Programming (continued) Inheritance – Derive the interface and behaviors from another class – Inherits keyword allows you to inherit from another.NET class – All objects are inherited from the System.Object – Properties like ToString apply to most objects Encapsulation – Inner workings of the object are maintained within the object

Introduction to ASP.NET, Second Edition11 Introduction to Visual Basic.NET Windows Application – User interface is called the Form Windows Forms tab in the Toolbox – Created from System.Windows.Forms Web Pages – Code behind the page contains class definition Inherits keyword – Create classes in a file, or code behind the page Import the class into the page Create a new object using the class

Introduction to ASP.NET, Second Edition12 Creating a Class TaraStoreClass.vb (Page 215 ) Create Chapter5 Web application, create images folder, import images, and data files Create the TaraStoreClass class (TaraStoreClass.vb) Modify the Code View Options – Automatic outlining and add line numbers Create Ch5Class (in ClassVariables.aspx) – Retrieve values inherited from TaraStoreClass View the IL using the ILDASM

Introduction to ASP.NET, Second Edition13 TaraStoreClass.vb (continued)

Introduction to ASP.NET, Second Edition14 TaraStoreClass.vb (continued)

Introduction to ASP.NET, Second Edition15 ClassVariables.aspx

Introduction to ASP.NET, Second Edition16 ClassVariables.aspx (continued)

Introduction to ASP.NET, Second Edition17 ClassVariables.aspx (continued)

Introduction to ASP.NET, Second Edition18 Chapter5.dll

Introduction to ASP.NET, Second Edition19 Variables Declaring a variable – Declaration keywords, variable name, data type Data type identifies what kind of data the variable can store – Process of reserving the memory space for the variable before it is used in the program – Declare all variables before they are used

Introduction to ASP.NET, Second Edition20 Variable Declaration Where the variable is defined determines where the variable can be used within the application – Scope – where access variable – Lifetime – how long variable and its value persist in memory

Introduction to ASP.NET, Second Edition21 Variable Declaration (continued) Keywords specify the variable scope – Private - available only to code within the local class – Public - used outside the class – Friend - used only within the current application or project

Introduction to ASP.NET, Second Edition22 Variable Declaration (continued)

Introduction to ASP.NET, Second Edition23 Variable Declaration (continued) Naming variables – Descriptive name – No commands or keywords – Begin with a letter – Do not use a period or space – Avoid special characters except underscore – Visual Basic.NET commands and variables are not case sensitive – First letter of each word is usually capitalized

Introduction to ASP.NET, Second Edition24 Variable Declaration (continued) First Three Characters Identify the Data Type Data TypePrefixSample Variable Name BooleanBlnBlnMember ByteBytBytZero CharChrChrLetter DateDatDatBirthdate DoubleDblDblWeight DecimalDecDecProductPrice IntegerIntIntNumberProducts LongLngLngSalary SingleSngSngAverage ShortShoShoYears StringStrStrLastName

Introduction to ASP.NET, Second Edition25 Assigning Values to Variables The assignment operator is the equal sign (=) – Remember Visual Basic.NET is NOT case sensitive. However, Visual Studio.NET will place Dim, As, and String in upper case characters Dim LastName, FirstName as String Dim StoreName As String = " Tara Store "

Introduction to ASP.NET, Second Edition26 Constants A variable that does not change Examples - tax rates, shipping fees, and values used in mathematical equations Declare a constant – Const keyword - Name is usually all uppercase – When you declare a constant, you need to assign the value to the constant Const TAXRATE As Integer = 8

Introduction to ASP.NET, Second Edition27 Concatenation Process of joining one or more strings Concatenation operator (&) – Can also use (+) only with strings Join a literal string, or the result returned from an expression, or a variable that contains a string Dim lblControlContent = Ch5Class.StoreName.ToString() _ & " " & Ch5Class.Store .ToString() lblContact.Text = lblControlContent

Introduction to ASP.NET, Second Edition28 Data Types Reference types – Strings, classes, arrays, collections, and objects – Memory addresses stored in the managed heap Value types – Referred to as primitive types or structures – Stores the actual data in the stack – Boolean and Char – DateTime (Date in Visual Basic.NET) – All numeric data types

Introduction to ASP.NET, Second Edition29 String Strings are variable in length – Do not have to specify the number of characters Several built-in methods manipulate strings – LCase and UCase - converts case to lower and upper Dim Password As String Password = LCase(txtPassword.Value) LblPassword.Text = Password

Introduction to ASP.NET, Second Edition30 Char Store a single text value as a number between 0 and 65,535 Represents a character in categories such as digit, letter, punctuation, and control characters

Introduction to ASP.NET, Second Edition31 Numeric Byte - stores an integer between 0 and 255 Short - 16-bit number from -32,768 to 32,767 Integer - 32-bit whole number Long - 64-bit number Real number data types – Single - a single-precision floating point number – Double - larger numbers than the single data type – Decimal - up to 28 decimal places and often used to store currency data

Introduction to ASP.NET, Second Edition32 DateTime Dates between 01/01/0001 and 12/31/9999 Formats are mm/dd/yyyy and hh:mm:ss Enclosed within a pair of pound signs Dim MyBirthday As DateTime MyBirthday = #3/22/2002#

Introduction to ASP.NET, Second Edition33 Object Browser

Introduction to ASP.NET, Second Edition34 Boolean Two possible values: True or False In binary math: – 1 represents true – 0 represents false In Visual Studio.NET – True value is converted to -1 – False value is converted to 0

Introduction to ASP.NET, Second Edition35 Using a Property to Retrieve and Set the Value of a Variable Use a variable outside of a class – Use the property function – Declare the variable public Property methods – Used to keep private variables – To retrieve and set the variable’s value Set the value and retrieve them indirectly

Introduction to ASP.NET, Second Edition36 Using a Property to Retrieve and Set the Value of a Variable (continued) ReadOnly prevents you from writing to the property WriteOnly allows the value to be changed, but not retrieved from the property Public ReadOnly Property NewStoreName() As String Public WriteOnly Property NewStoreName()  As String

Introduction to ASP.NET, Second Edition37 Collections Data stored in structures called collections – System.Collections namespace provides access to classes that manage data – Each item is referred to as an element These five collections – ArrayList, HashTable, and SortedList - access any element without having to rotate through the other elements – Queue and Stack - rotate through the collection sequentially to locate an element

Introduction to ASP.NET, Second Edition38 The ArrayList Stores each item in sequential order – Each item is indexed with a number – Do not need to define the size of the ArrayList – Each item is identified using an index number that indicates its position Zero-based - first item is at position 0 – ArrayList size of 3 means it has 4 items

Introduction to ASP.NET, Second Edition39 The ArrayList (continued) Create an ArrayList Dim StateAbbrev As New ArrayList StateAbbrev.Add("IL") StateAbbrev.Add("MI") StateAbbrev.Add("IN") Retrieve the value individually Response.Write(StateAbbrev(0)) Insert an element into the first position and remove it StateAbbrev.Insert(0, "OK") StateAbbrev.Remove("OK")

Introduction to ASP.NET, Second Edition40 The ArrayList (continued) Properties and Methods – Add and Remove - add or delete a single element – Insert and RemoveAt - add and remove elements at a specific index position – AddRange and RemoveRange - add or remove a group of elements – IndexOf - find the position of the element in the list A value of -1 means the element was not found in the list. – Count - identifies the number of items in the array which will be the largest index number plus 1. – Clear - remove all of the elements

Introduction to ASP.NET, Second Edition41 The HashTables Creates the index of elements using an alphanumeric key like an encyclopedia – keys - a collection of alphanumeric values – values - a collection of elements Add and Remove method – Items added using key and value pair separated with a comma Key passed with quotation marks Second parameter is the value

Introduction to ASP.NET, Second Edition42 Other Collections The SortedList Class - Indexed by both the key and the item so the index position will change frequently The Queue Class - sequential access to the elements – Stores them in First In, First Out (FIFO) Roller coaster ride People in the first car are let out first The Stack class - sequential access – Stores them in Last In, First Out (LIFO) order Line in a theatre, church, or crowded elevator First one to enter the room is the last one to leave

Introduction to ASP.NET, Second Edition43 Procedures Subprocedures – Do not return values – Cannot be used in an expression value Event Procedures – Not executed until an event triggers the procedure – Known as an event procedure – Does not return a value – Page_Load event triggered when the page is loaded Functions – A block of code that is grouped into a named unit. – Built-in functions inherit from a.NET Framework class – User defined functions

Introduction to ASP.NET, Second Edition44 Subprocedures Other keywords - Public or Private, Exit Sub Sub SubprocedureName(parameters) Action and Control Statements End Sub Call keyword – calls the procedure [Call] SubprocedureName(arguments)

Introduction to ASP.NET, Second Edition45 Event Procedure Event Names – Based on object name and event name – Identified with the prefix “on” and event name – Underscore (_) separate object and event name Sub objectName_eventHandler  (sender as Object, e as EventArgs) action and control statements End Sub

Introduction to ASP.NET, Second Edition46 Functions Are declared Public functions - visible to all other functions Private functions - only available within the context where they are declared Public Function GetStoreName() As Integer 'This function returns an integer Return End Function

Introduction to ASP.NET, Second Edition47 Passing an Argument to a Function A pair of parentheses follows with zero or more arguments, also known as parameters, which are passed to the function when it is called – If no arguments are passed, you use an empty pair of parentheses – If multiple arguments are used, you use a comma to separate each argument

Introduction to ASP.NET, Second Edition48 Returning a Value From a Function & Exiting a Function Keyword Return – Identify the value returned to the function call Exiting a Function – Exit Function keywords – A jumping control; jumping controls allow you to temporarily halt the execution of a code block, and move to another section of code outside the function

Introduction to ASP.NET, Second Edition49 Exiting a Function Public Function GetStoreName() As String Dim UserName As String UserName = txtUserName.Text.ToString If UserName = "Admin" then Return "Welcome Administrator!" Exit Function Else Return "Welcome!" Exit Function End If End Function

Introduction to ASP.NET, Second Edition50 Creating a Function Public Class TaraStoreClass Public Function GetStoreName() As String Return " Tara Store " End Function End Class GetTheFunction(New TaraStoreClass().GetStoreName)

Introduction to ASP.NET, Second Edition51 Using Visual Basic.NET in a Web Page SampleUsingVB.aspx (Page 239)

Introduction to ASP.NET, Second Edition52 Using Visual Basic.NET in a Web Page SampleUsingVB.aspx (continued)

Introduction to ASP.NET, Second Edition53 Using Visual Basic.NET in a Web Page SampleUsingVB.aspx (continued)

Introduction to ASP.NET, Second Edition54 Using Visual Basic.NET in a Web Page SampleUsingVB.aspx (continued)

Introduction to ASP.NET, Second Edition55 Using Visual Basic.NET in a Web Page SampleUsingVB.aspx (continued)

Introduction to ASP.NET, Second Edition56 Introduction to C# Syntax similar to JavaScript and C++ Compiled by the C# compiler – into the same managed Intermediate Language code that is also generated by the Visual Basic.NET compiler Base Classes and development environment are available across programming languages Access to the same Windows Form tools and ASP.NET Web Form tools

Introduction to ASP.NET, Second Edition57 Introduction to C# (continued) Language Differences – C# is case sensitive – Array using C#, use square brackets around index position – One or more statements; enclose code in curly braces { } – Assign a value to a variable, specify the data type first, then specify the variable name String StoreName = "Tara Store"; int counter = 1;

Introduction to ASP.NET, Second Edition58 Introduction to C# (continued) Comments in C# are similar to comments in JavaScript // This is a single line comment /* This is a multiline comment Always document your code */ Declare the variable public in C# – Use all lower case letters for the keyword public Declaration of variables

Introduction to ASP.NET, Second Edition59 Introduction to C# (continued) C# Sample String s1; String s2 = "Welcome to "; s2 += "Tara Store"; s1 = s2 + " !!!"; Label1.Text = s1.ToString(); J# Sample (this is the sample shown in the book) String s1; String s2 = "Welcome to "; s2 += "Tara Store"; s1 = s2 + " !!!"; Label1.set_Text(s1);

Introduction to ASP.NET, Second Edition60 Introduction to C# (continued) JScript Sample - this goes inline in the HTML code view <% // Write the message to the Web page var s1 : String; var s2 : String = "Welcome to "; s2 += "Tara Store"; s1 = s2 + " !!!"; Response.Write(s1); Response.Write(s3); %>

Introduction to ASP.NET, Second Edition61 Introduction to C# (continued) StringBuilder Class – Import System and System.Text C# Sample StringBuilder s3 = new StringBuilder(); s3.Append("Welcome to "); s3.Append("Tara Store"); s3.Append(" !!!"); Label1.Text = s3.ToString(); J# Sample (this is the sample shown in the book) StringBuilder s3 = new StringBuilder(); s3.Append("Welcome to "); s3.Append("Tara Store"); s3.Append(" !!!"); Label1.set_Text(s3.ToString());

Introduction to ASP.NET, Second Edition62 Summary Process of creating an object from a class is instantiation Create multiple classes within a single class file Assign a data type to a variable when the variable is created Properties set the value of a variable defined within an object Constants store values in variables that do not change within the application Concatenation operator is the ampersand

Introduction to ASP.NET, Second Edition63 Summary (continued) Each item in the collection is referred to by its index position Procedures organize the order in which the code is executed Event handlers execute code when an event occurs Functions return values C# is a new programming language that can be used to create ASP.NET applications