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 991<br />

70 <br />

73 <br />

74<br />

75 <br />

76 <br />

77 <br />

Fig. 20.29 Options supplied on an ASPX page (part 3 of 3).<br />

Every Web Form includes an HttpSessionState object, which is accessible<br />

through property Session of class Page. Throughout this section, we use property Session<br />

<strong>to</strong> manipulate our page’s HttpSessionState object. When the Web page is<br />

requested, an HttpSessionState object is created and assigned <strong>to</strong> the Page’s Session<br />

property. As a result, we often refer <strong>to</strong> property Session as the Session object.<br />

When the user presses Submit, submitBut<strong>to</strong>n_Click is invoked in the code-behind<br />

file (Fig. 20.30). Method submitBut<strong>to</strong>n_Click responds by adding a key-value pair<br />

<strong>to</strong> our Session object, specifying the language chosen and the ISBN number for a book<br />

on that language. These key-value pairs are often referred <strong>to</strong> as session items. Next, a postback<br />

occurs. Each time the user clicks Submit, submitBut<strong>to</strong>n_Click adds a new session<br />

item <strong>to</strong> the HttpSessionState object. Because much of this example is identical<br />

<strong>to</strong> the last example, we concentrate on the new features.<br />

1 ' Fig. 20.30: OptionsPge2.aspx.vb<br />

2 ' A listing of programming languages,<br />

3 ' cookie is created based on choice made.<br />

4<br />

5 Imports System.Web.UI.WebControls<br />

6<br />

7 Public Class Options2<br />

8 Inherits System.Web.UI.Page<br />

9 Protected WithEvents languageLink As HyperLink<br />

10 Protected WithEvents recommendationsLink As HyperLink<br />

11 Protected WithEvents LanguageList As RadioBut<strong>to</strong>nList<br />

12 Protected WithEvents idLabel As Label<br />

13 Protected WithEvents timeOutLabel As Label<br />

14 Protected WithEvents promptLabel As Label<br />

15 Protected WithEvents welcomeLabel As Label<br />

16 Protected WithEvents submitBut<strong>to</strong>n As But<strong>to</strong>n<br />

17 Private books = New Hashtable()<br />

18<br />

19 ' <strong>Visual</strong> Studio .<strong>NET</strong> generated code<br />

20<br />

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

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

23<br />

24 InitializeComponent()<br />

25<br />

Fig. 20.30 Sessions are created for each user in an ASP .<strong>NET</strong> Web application (part 1<br />

of 4).

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

Saved successfully!

Ooh no, something went wrong!