Skip to main content Skip to footer

Integrating ASP.NET Personalization with C1WebSchedule

Applies To:

WebSchedule for ASP.NET

Author:

John Juback

Published On:

3/16/2007

The 2007 v1 release of ComponentOne Studio Enterprise introduced two new components, C1WebSchedule and C1WebCalendar, for developing Outlook-style scheduling applications for the Web. C1WebCalendar provides navigation and date range selection for an associated C1WebSchedule control, which displays appointments in day, week, work week, or monthly views.

Although C1WebSchedule includes a built-in data layer that automatically manages the storage of appointments and related collections, the application developer is responsible for implementing storage on a per-user basis. This article illustrates how to use the personalization and profile features of ASP.NET 2.0 to implement private schedules with authentication.

To see the sample site in action, visit the following URL:

[http://helpcentral.componentone.com/C1WebScheduleSample](http://helpcentral.componentone.com/C1WebScheduleSample)

This will open a page with three components:

C1WebCalendar

This control displays months along the left side of the page. The number of months displayed is controlled by setting the MonthRows property at design time. The topmost month includes navigation links.

LoginView

This control appears below the calendar. It uses templates to display appropriate controls for the anonymous and logged in states.

C1WebSchedule

The right side of the page consists of a single C1WebSchedule control that displays appointments in a scrollable grid. Selecting a date in the calendar also changes the date displayed in the schedule.

Creating and authenticating users

When you visit the site as an anonymous user, the Log In box contains user name and password controls as shown in the preceding figure. Although you can use the calendar control to navigate the schedule, no appointments are displayed, and double-clicking in a grid row has no effect. In order to become an authenticated user, you must first click the Create User button to set up a new account. This will take you to another page that prompts for your user profile.

In this page, a CreateUserWizard control is used to display a simple form that validates data entry by verifying that the password strings match (and are sufficiently complex) and by ensuring that all other fields are filled in. At design time, the ContinueDestinationPageUrl property is set to Default.aspx so that successful account creation will redirect to the main page. At that point, you are authenticated and can interact with the C1WebSchedule control to create appointments.

Note that the login controls below the calendar have been replaced by a welcome message and a Logout link. This is handled automatically by the LoggedInTemplate of the LoginView control, which contains a LoginName control for the welcome message and a LoginStatus control for the Logout link. Clicking the link restores the page to its original, unauthenticated state and removes all appointments from the display. However, the appointments remain in the database and will be displayed again the next time you log in.

Working with appointments

C1WebSchedule contains built-in "dialog boxes" similar to those in Microsoft Outlook. To create a new appointment, double-click the desired grid row in the schedule control, fill in the Subject line, confirm the starting and ending dates and times, then click the Save and Close button. C1WebSchedule also manages collections of related items, such as Labels (the multicolored drop-down control in the following figure).

In this application, only appointment records are saved on a per-user basis; the other collections use the built-in default values. However, you can apply the personalization techniques outlined in this article to other collections if you want to allow your users to define their own appointment categories, for example.

Within the appointment dialog, you can click the Recurrence button to set up multiple instances of an appointment based on its frequency (daily, weekly, monthly, yearly) and date ranges, including appointments that end after a specified number of occurrences (or not at all).

NOTE: Recurrence pattern support was added in build 2.0.20071.209, after the initial 2007 v1 release. At design time, open the About box of a C1WebSchedule control to verify its version number.

To enable personalization for an ASP.NET project, follow these steps:

  1. Open the web site in Visual Studio, then select ASP.NET Configuration from the Website menu. This will open the ASP.NET Web Site Administration Tool.
  2. In the Security tab, click Select authentication type, then choose the Internet option to provide forms-based authentication as in this sample.
  3. Close the Web Site Administration Tool. Refresh the App_Data folder in Solution Explorer to reveal a SQL Server 2005 Express database named ASPNETDB.MDF.

In code, the Profile object represents the values of named properties for individual users. You can think of the Profile object as a Session object with persistence. To define the profile properties, just add them to the web.config file as in the following example, which declares a single string property named UserId:








After you build the project, you will be able to access the properties with Intellisense while coding. The build process dynamically creates a ProfileCommon class that inherits from System.Web.Profile.ProfileBase. When you assign a value to a profile property, that value is stored in ASPNETDB.MDF for future sessions.

The Page_Load handler for the sample application checks to see if the current user is authenticated by checking the value of the IsAnonymous property. For anonymous users, the handler turns off all editing options in the schedule control. For authenticated users, the handler retrieves the underlying database id (a GUID) for the current user, converts it to a string, and saves it in the UserId profile property.

protected void Page_Load(object sender, EventArgs e)  
{  
    if (!IsPostBack)  
    {  
        if (Profile.IsAnonymous)  
        {  
            C1WebSchedule1.EditOptions = C1.Web.C1Schedule.C1WebScheduleEditOptions.None;  
        }  
        else  
        {  
            string name = Profile.UserName;  
            MembershipUser user = Membership.GetUser(name, false);  
            string id = user.ProviderUserKey.ToString();  
            Profile.UserId = id;  
            WebScheduleDataSource.SelectParameters["UserId"].DefaultValue = id;  
        }  
    }  
}

The id is then used as a parameter for the SELECT statement that is used to populate the appointments in WebScheduleDataSource, which is an Access data source bound to C1WebSchedule. The following figure shows the field mappings that were specified at design time. Note that the Id field is a GUID that uniquely identifies each appointment, while the UserId field is used to select appointments that belong to individual users.

The only other piece of code in the sample is a handler for the Inserting event of the data source, which injects the UserId previously saved in the profile into the INSERT statement that executes when the user saves a newly created appointment:

protected void WebScheduleDataSource_Inserting(object sender, SqlDataSourceCommandEventArgs e)  
{  
    e.Command.Parameters["UserId"].Value = Profile.UserId;  
}

No additional coding is needed for updates, since the correct UserId is already in place.

A full discussion of the personalization features of ASP.NET 2.0 is beyond the scope of this article. For more information, visit the following link:

[Storing User Information with ASP.NET 2.0 Profiles](http://msdn2.microsoft.com/en-us/library/ms379605(VS.80).aspx)

To download the source code for the sample site, visit the following link:

[PersonalScheduleSite.zip](//cdn.mescius.io/assets/developer/blogs/legacy/c1/2007/3/personalschedulesite.zip)

Note that this zip file does not include ASPNETDB.MDF. Use the Web Site Administration Tool as described earlier in this article to create it. Or, you can use the command line utility aspnet_regsql.exe to add the necessary tables and stored procedures to an existing instance of SQL Server.

MESCIUS inc.

comments powered by Disqus