Personalizing with Complex Types

While personalizing a site for your users is terrific, to make a useful commercial site, you often have to store complex user-defined types (classes) or collections.

In the next exercise, you’ll edit the web.config file to add a collection of strings called CHOSENBOOKS. Doing so will allow the user to choose one or more books and have those choices stored in the user’s profile.

Add a line to web.config for your new property:

        <add name="lastName" />
        <add name="firstName" />
        <add name="phoneNumber" />
        <add name="birthDate" type="System.DateTime"/>
        <add name="CHOSENBOOKS"
            type="System.Collections.Specialized.StringCollection" />

To see this collection at work, edit the page ProfileInfo.aspx, inserting a row with a checkbox list just above the row with the Save button. While you are there, let’s rename the text boxes to our normal naming scheme and fix the corresponding code. The complete content file is shown in Example 13-2.

Example 13-2. Revised ProfileInfo.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ProfileInfo.aspx.cs"
   Inherits="ProfileInfo_aspx" %>


<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
                <td>First Name: </td>
                <td style="width: 193px">
                   <asp:TextBox ID="txtFirstName" ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.