30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 20 ASP .<strong>NET</strong>, Web Forms and Web Controls 949<br />

19 ' This call is required by the Web Form Designer<br />

20 Private Sub InitializeComponent()<br />

21 End Sub<br />

22<br />

23 Private Sub Page_Init(ByVal sender As System.Object, _<br />

24 ByVal e As System.EventArgs) Handles MyBase.Init<br />

25<br />

26 InitializeComponent()<br />

27<br />

28 timeLabel.Text = _<br />

29 String.Format("{0:D2}:{1:D2}:{2:D2}", _<br />

30 DateTime.Now.Hour, DateTime.Now.Minute, _<br />

31 DateTime.Now.Second)<br />

32 End Sub ' Page_Init<br />

33<br />

34 Private Sub Page_Load(ByVal sender As System.Object, _<br />

35 ByVal e As System.EventArgs) Handles MyBase.Load<br />

36 ' Put user code <strong>to</strong> initialize the page here<br />

37 End Sub ' Page_Load<br />

38 End Class ' WebTimer<br />

Fig. 20.5 Code-behind file for a page that displays the Web server’s time (part 2 of 2).<br />

Notice the Imports statements in lines 5–8. These statements specify namespaces<br />

that contain classes for developing Web-based applications. The key namespace on which<br />

we initially focus is System.Web, which contains classes that manage client requests and<br />

server responses. The other namespaces define the controls available and how they can be<br />

manipulated; these are discussed throughout the chapter as they become more relevant.<br />

Line 10 begins the class definition for WebTimer, which inherits from class Page.<br />

This class defines the requested Web page and is located in the System.Web.UI<br />

namespace (line 7), which contains classes pertinent <strong>to</strong> the creation of Web-based applications<br />

and controls. Class Page also provides event handlers and objects necessary for creating<br />

Web-based applications. In addition <strong>to</strong> the Page class (from which all Web<br />

applications directly or indirectly inherit), System.Web.UI also includes the Control<br />

class. This class is the base class that provides common functionality for all Web controls.

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

Saved successfully!

Ooh no, something went wrong!