[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Collapse]Getting Started
   Tutorial 1 - Your First Data-Aware Application with XPO
   Tutorial 2 - Relations (One to Many)
   Tutorial 3 - Querying Data
   Tutorial 4 - A Windows Forms Application for Data Editing
   Tutorial 5 - An ASP .NET Application for Data Editing
   Tutorial 6 - A Simple Guestbook (ASP.NET)
   Getting Started with .NET Core
 [Expand]Fundamentals
 [Expand]Feature Center
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Examples
 [Expand]Member Tables
 [Expand]API Reference
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial 6 - A Simple Guestbook (ASP.NET)

A guest book is a web site page that provides site visitors with a simple way to post their comments about your web site. In this tutorial, you will learn how to make a simple guest book.

An edit form is used to enable visitors to enter their name, email address, and the comment title and text. Comments will be displayed by the ASPxNewsControl. The image below illustrates a sample guest book.

Follow the steps below to create your guest book. In this tutorial, it is assumed that the guest book's edit form has already been created.

  • Step 1: Define a Persistent Data Store
  • Step 2: Connect XPO to a Database Server
  • Step 3: Customize the XpoDataSource Component
  • Step 4: Create XPO Sessions
  • Step 5: Create the ASPxNewsControl and Bind it to a Data Source
  • Step 6: Create the New Comments Form
  • Step 7: Save New Comments

Expanded Implementation

Step 1: Define a Persistent Data Store

Define a persistent object class. Persistent objects are stored as records in database tables, and encapsulate all relationships. The class properties are stored as field values in the records, and the collection of persistent objects is the equivalent of a data table. All you need to do is to define a persistent object class, and XPO will automatically generate a database (MS Access Database by default) and the required table structure for it.

  • Add a new class to the project (the Comment.cs file).
  • Define the "Comment" persistent class as shown below:

    The Date, Title and Text properties of this class represent the values of the corresponding fields in the database table.

    Note

    Note that the property implementations in these samples do not include all of the recommended code in the setters. The sample code has been shortened for simplicity. If you follow Tutorial 4 - A Windows Forms Application for Data Editing, you can see the recommended approach to implementing property setters.

 

Step 2: Connect XPO to a Database Server

Connect XPO to your database server. To do this, handle the Application_Start event in the Global.asax module of your website to create an IDataLayer object. It is recommended that you use the ThreadSafeDataLayer in ASP.NET applications.

Note

The image below shows how to add the Global.asax module:

 

Step 3: Customize the XpoDataSource Component

To retrieve persistent objects from a database, use the XpoDataSource component. Place it on your page, rebuild the project, and specify the XpoDataSource.TypeName property.

 

Step 4: Create XPO Sessions

Handle the page's Init event to create a Session for the XpoDataSource component. The session must be linked to your DataLayer.

It is recommended that you create an XPO Session for each request. To do this, create a new session for each page.

 

Step 5: Create the ASPxNewsControl and Bind it to a Data Source

Place the ASPxNewsControl onto a Web form and bind it to the XpoDataSource component.

 

Step 6: Create the New Comments Form

Drop three ASPxTextBox controls onto the form to allow users to specify their name, email address, and title. Rename the text boxes as tboxName, tboxEmail, and tboxTitle. Add an ASPxMemo control that will be used to enter the actual comments. Add an ASPxButton and set its caption to "Submit".

 

Step 7: Save New Comments

Handle the Submit button's Click event to save a new comment. Once a visitor has clicked this button, a new Comment is initialized and saved to the database.

Is this topic helpful?​​​​​​​