Click here to Skip to main content
13,147,044 members (63,277 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Revisions
Add your own
alternative version


12 bookmarked
Posted 5 Oct 2012

Simple "Contact Book" web application using VisualJS.NET, Fluent NHibernate and ASP.NET Web Forms on MS SQL Server 2012

, 1 Oct 2012
Rate this:
Please Sign up or sign in to vote.
Simple "Contact Book" web application using VisualJS.NET, Fluent NHibernate and ASP.NET Web Forms on MS SQL Server 2012
This is an old version of the currently published article.


RAD technique is one of many methodologies of developing software. It has its pros and cons, but is useful in some scenarios. 

Let's take a look at the process of creating web applications using RAD methodology offered by the well known VisualJS.NET library, using the most popular .NET ORM - NHibernate on the ASP.NET framework with MS SQL Server as data backend.


Basic C# and ASP.NET Web forms skills are required

Using the code

We will keep the code simple, without any additional layers of abstraction not to obscure the general view. 


Let's start with creating a database. We are using a single table, although in a real life scenario the schema would be more advanced. Using SQL Server Management Studio we create the following table: 

<o:p />

We create ASP.NET web application project using Visual Studio 2010.<o:p />

That was easy and fast. Now let's put Fluent NHibernate into our project. Using NuGet package directly from Visual Studio takes us no more than a minute. Fluent NHibernate is a library making core NHibernate much more... fluent ( It uses fluent coding methodology to work with configuration, mappings, schemas and many more aspects involved in using NHibernate. Additionaly it forgets about xml mapping files and move that functionality right into a code. Fluently of course.

Let's take a look at some code:

Our single entity class (to have a clean representation of our database table "Contact") 

public class Contact
    public virtual int ID { get; protected internal set; }
    public virtual string Firstname { get; set; }
    public virtual string Surname { get; set; }
    public virtual string PhoneNumber { get; set; }
    public virtual string Gender { get; set; }
    public virtual string Address { get; set; }

backed up with mapping class to let know NHibernate what are the roles of properties in our entity class. This mapping can be made in automated way as well. 

<o:p />

public class ContactMap : ClassMap<Contact>
    public ContactMap()
        Id(x => x.ID);
        Map(x => x.Firstname);
        Map(x => x.Surname);
        Map(x => x.PhoneNumber);
        Map(x => x.Gender);
        Map(x => x.Address);

Session object that is our base object for interaction with NHibernate and database. It also incorporates configuration of our database. Here in simple form: 

<o:p />

public class SessionFactoryManager
       public static ISessionFactory CreateSessionFactory()
           return Fluently.Configure()
           .ConnectionString(c => c
           .Mappings(m => m
Time for VisualJS.NET.
Again using nuget package makes downloading needed library very fast and simple. After installation we need to add
VisualJS.NET support to our project. With single right button click on our project name and choosing "Add VisualJS.NET support" we add references and sample pages to our project.

Now let's create some UI.

We want use the goodness of VisualJS.NET library, so we create visualjs form by right clicking on our project and selecting new appeared option "Add form". Let's name it "ContactBook".

First we want to embed our future contact book

VisualJS.NET control in existing aspx page. Let's put it on already created by ASP.NET project template default.aspx page. To do this we add to default.aspx VisualJSControl right from the Toolbox. Then we fill FormName and HandlerUrl properties of VisualJSControl with appropriate values: 

<o:p />


Now our default.aspx page will display our Contact Book. Let's create it.

We will use one view - ContactBook for general links and listing of contacts and second reusable view - AddEditContact for creating and updating our contacts: 



On the ContactBook view we put VisualJS.NET ListView control for listing our contacts. We add appropriate colums programmatically or in designer and we fetch data from database: 

using (var session = sessionFactory.OpenSession())
      var contacts = session.CreateCriteria(typeof(Contact)).List<Contact>();
      foreach (var c in contacts)
         ListView.ListViewItem lvi = new ListView.ListViewItem() { Tag = c.ID };
         lvi.SubItems.Add(new ListView.ListViewSubItem(c.Firstname) { Name = "Firstname" });
         lvi.SubItems.Add(new ListView.ListViewSubItem(c.Surname) { Name = "Surname" });
         lvi.SubItems.Add(new ListView.ListViewSubItem(c.Gender) { Name = "Gender" });
         lvi.SubItems.Add(new ListView.ListViewSubItem(c.PhoneNumber) { Name = "PhoneNumber"});
         lvi.SubItems.Add(new ListView.ListViewSubItem(c.Address) { Name = "Address" });

We add three links for adding, editing and deleting contact. For all of those actions we use easy to do MessageBox and Dialog. The rest of CRUD actions agains database are similar to above code and you can find it in the source. You should use transactions in real life application. Here is the sample of add contact link handler showing windows forms style of displaying the dialog window: 

<o:p />

private void lnkAddContact_LinkClicked(object sender,  System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
            var f = new AddEditContact();
            f.FormClosed += new System.Windows.Forms.FormClosedEventHandler(f_FormClosed);

Now aforementioned AddEditContact form shaped to show as a window. We use controls from VisualJS.NET
toolbox including JButtons. We reuse that form for both adding a new and editing an existing contact. We use the built in VisualJS.NET validation and error displaying for textboxes which further makes our project a real RAD driven.

Before building attached project please download required VisualJS.NET libraries.  

Download sample 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michał Maniewski
Software Developer
Poland Poland
No Biography provided

You may also be interested in...

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
QuestionVisual JS.NET licensing Pin
DumpsterJuice10-Oct-12 4:05
memberDumpsterJuice10-Oct-12 4:05 
AnswerRe: Visual JS.NET licensing Pin
Jankinsoo12-Oct-12 1:52
memberJankinsoo12-Oct-12 1:52 
QuestionField types Pin
Olivier Giulieri5-Oct-12 18:25
memberOlivier Giulieri5-Oct-12 18:25 
GeneralMy vote of 4 Pin
Oshtri Deka2-Oct-12 10:52
memberOshtri Deka2-Oct-12 10:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 1 Oct 2012
Article Copyright 2012 by Michał Maniewski
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid