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> 97//Constructor function has the same name as the classpublic OutClass(){header = "From your class:";}}//Class methodpublic string sendMsg(string fromClass){return header + fromClass;}This class has a single method, sendMsg(), and a single property, header. Becausethe sendMsg() method is public, you can access it from another class.Accessing the C# Class from the C# Partial ClassThe final step is to modify the C# partial class that is automatically generated. Open thepartial C# class, and within the Page_Load function, begin adding code as shown inFigure 4-7. To instantiate an instance of the OutClass within the partial class, simplydeclare the class and then instantiate it as shown in Line 9 in Figure 4-7. Once you haveinstantiated the class, IntelliSense recognizes the OutClass method, making it very easyto develop with user classes you’ve developed yourself.Figure 4-7 IntelliSense recognizes methods from instantiated classes.

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

Saved successfully!

Ooh no, something went wrong!