13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Doing More with C# and <strong>ASP</strong>.<strong>NET</strong> 99In looking at Figure 4-8, you can see the contributions of each of three main elements:●●●The window displaying the text (TextBox from <strong>ASP</strong>.<strong>NET</strong>)“From your class:” (content of the C# class property, header)“The OutClass class” (text in the parameter of the sendMsg method from the ClassOutclass instance in the partial class)As you can see, each of the three scripts made a contribution. The main lessonfrom this, though, is that you can access C# classes and structures from the partial classassociated with the <strong>ASP</strong>.<strong>NET</strong> controls and forms.Using InterfacesLike classes, interfaces in C# can be used in conjunction with an <strong>ASP</strong>.<strong>NET</strong> application.Generally, interfaces are used in more sophisticated structures, and while you may notneed them to learn <strong>ASP</strong>.<strong>NET</strong>, knowing how to use them with <strong>ASP</strong>.<strong>NET</strong> may prove tobe valuable with more advanced structures found in object-oriented programming or indesign patterns.Like a class, an interface is an abstraction to be employed concretely in specificimplementations. Generally, interfaces describe a group of related functionalities. Youmight think of a class as an abstraction of an object and of an interface as an abstractionof a method. An interface cannot be directly instantiated, but must be instantiated fromconcrete classes that implement an interface. Moreover, a key good practice is to programto an interface and not to an implementation. For the most part, this means that the typingwill be to the interface, but the instantiation is to the class that implements the interface.To better understand interfaces and their use, look at a good book on OOP or C#.Here, you will see how an interface can be used with an <strong>ASP</strong>.<strong>NET</strong> web application. In thisnext sample application, you will see a simple interface with output to an <strong>ASP</strong>.<strong>NET</strong> form.The following steps show how:1. Create a new web site in Visual Studio 2008 using the name Interface Test.2. Change the default name of the <strong>ASP</strong>X file to Iface and then enter the following code.<strong>ASP</strong>.<strong>NET</strong> Iface.aspx

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!