Summary


In this hour we reexamined the concepts behind objects and classes. To use an object, we first must create it. This is accomplished using the Visual Basic New keyword along with a constructor. As we saw, a constructor is a method that has the same name as the class and returns an instance of the class. For example, to create an instance of the SqlCommand class, we could use

Dim myCommand as SqlCommand myCommand = New SqlCommand() 


After an object has been created, we can set its properties, call its methods, and create event handlers. An object's property can be accessed by listing the object's name, followed by a period, followed by the property name. For example, to access the CommandText property of the myCommand object, we would use the following syntax:

myCommand.CommandText 


Properties have the same semantics as ordinary variables; they have a type and can be used in expressions or assigned values.

An object's method is called by listing the object's name, followed by a period, followed by the method's name. Methods are like subroutines and functions in that they may accept zero or more input parameters and can optionally return a value.

Objects can also have a number of events that can fire at different times; when an event fires, we may want to execute some code. Event handlers are special subroutines that are wired up to a particular event and execute when that specified event fires. Event handlers must accept two input parameters and use the Handles keyword to indicate the particular event that they execute in response to. Although an event handler's syntax can be entered manually, Visual Web Developer will gladly create the appropriate event handler syntax: You just specify the object and event from the drop-down lists at the top of the source code portion of an ASP.NET page.

This hour concludes our in-depth examination of Visual Basic. In the next hour we will look at the two ASP.NET Web controls that are used for displaying text: the Label and Literal Web controls. Following that, we will spend the next several hours examining how to collect and process user input.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net