Click here to Skip to main content
11,927,711 members (30,860 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked

ASP.NET Guest Entry Form

, 8 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Guest Entry form with an XML control.


Creating a Guest Book

I was not planning to reinvent the wheel but was trying to reuse the code presented earlier by one of the contributors, Guestbook for ASP.NET by Laurent Kempe. Since the code was in VC++ environment, I changed the code around to suit the VB.NET language. It turned out that between the time the original code was written and now, some of the overloaded functions in the viewPage of that article have become obsolete and other modifications were recommended, especially those pertaining to the XSLT Transform method. In this article, the XML control from the tool box is directly used to produce the guest book in HTML.

Fields required in the Guest Book

Generally, in Guest Books, it is required to collect information from a user browsing your site. You want a guest book to be included to obtain this information.

The following entries are needed in the Guest Book [you may customize]:

  • Name
  • Email
  • Homepage (URL)
  • Location
  • Comment
  • Date
  • a Boolean yes or no for private guests

Guest Entry Page UI

Since the information is to be retrieved from a guest entry page, add a web form and add the various controls. To get all the controls in good alignment, place them all inside a table contained in the form object of this web form.

The following HTML code shows the 'table' nested inside the 'form'.

<form id="Form1" method="post" runat="server">
<TABLE id="Table1" 
    style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" 
    cellSpacing="1" cellPadding="1" width="300" border="1">
            <asp:TextBox id="TextBoxName" runat="server">
            <asp:TextBox id="TextBoxEMail" runat="server">
        <TD>Homepage Title</TD>
            <asp:TextBox id="TextBoxHomepageTitle" runat="server">
        <TD>Homepage URL</TD>
            <asp:TextBox id="TextBoxHomepageURL" runat="server">
            <asp:TextBox id="TextBoxLocation" runat="server">
            <asp:TextBox id="TextBoxComments" runat="server">
            <asp:CheckBox id="CheckBoxPrivate" runat="server">
<asp:Button id="ButtonContinue" 
     style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 232px"
     runat="server" Text="SignUp" Width="144px" Height="32px">

Persistence of Guest Information

The user entered information will be placed in an XML file rather than in a database. This file shall be called the guestbook.xml and will have the structure shown in guestbook.html.

This is the guestbook.xml page that is already populated with some guest information.

<?xml version="1.0" encoding="ISO-8859-1"?>
  <guest private="yes">
    <name>David Frost</name>
    <homepage url="">David Frost News</homepage>
    <date>Friday, July 30, 2004 - 5:02:33 PM</date>
  <guest private="no">
    <homepage url="">UAE</homepage>
    <comment>test this one</comment>
    <date>Monday, July 26, 2004 - 5:11:12 PM</date>
  <guest private="yes">
    <name>Jayaram Krishnasawamy</name>
    <homepage url="">Programmer</homepage>
    <location>137 Tennyson Drive</location>
    <date>Thursday, July 23, 2004 -02:52 PM</date>

Code behind GuestEntry page with comments

When the submit button is clicked, the following code will be executed in order:

  1. The XMLDocument 'Guestbook.xml' will be loaded.
    Dim xdoc As New XmlDocument
  2. The checkbox entry will be retrieved and set to a text value.
    Dim prev As String
    If (CheckBoxPrivate.Checked) Then
        prev = "yes"
        prev = "no"
    End If
  3. A new document element is declared and defined as in next code, the checkbox called "private" is an attribute of the "guest" [root] element:
    Dim elem As XmlElement
    elem = xdoc.CreateElement("guest")
    elem.SetAttribute("private", prev)
  4. A new 'Guest' will be prepended to this file via:
  5. To add the other entries, a addTextElement function will be used, that takes,
    1. the XmlDocument as a constant,
    2. the element as a constant,
    3. the name of the element, and
    4. the location on the form from where it is retrieved.
  6. The code for the addTextElement function is as follows:
    Private Sub addTextElement(ByVal doc1 As XmlDocument, ByVal _
       elem1 As XmlElement, ByRef strTag As String, ByRef strVal _
       As String)
        Dim nodeElem = doc1.CreateElement(strTag)
        Dim nodeText = doc1.CreateTextNode(strVal)
    End Sub
  7. Add the other fields, "name", "email", "homepage" via:
    addTextElement(xdoc, elem, "name", TextBoxName.Text)
    addTextElement(xdoc, elem, "email", TextBoxEMail.Text)
    addTextElement(xdoc, elem, "homepage", TextBoxHomepageTitle.Text)
  8. The homepage element will store the URL as its attribute, and therefore we add the following code so that it will be homepage URL's attribute and will be taken from the guest entry form from a text box:
    Dim newatt As XmlAttribute
    newatt = xdoc.CreateAttribute("url")
    newatt.Value = TextBoxHomepageURL.Text
  9. We add two other fields, namely, "location", "comment" via:
    addTextElement(xdoc, elem, "location", TextBoxLocation.Text)
    addTextElement(xdoc, elem, "comment", TextBoxComments.Text)
  10. Next, the date field will be added combining data and time via:
    Dim strDate As String
    strDate = DateTime.Now.ToLongDateString() + " - " + _
    addTextElement(xdoc, elem, "date", strDate)
  11. Finally, the document will be saved via:

Viewing the guestbook.xml Page

We first need to create a XSL style sheet to transform the guestbook.xml to a HTML file. The following simple, no-frills file gb.xsl does the conversion.

<html xsl:version="1.0"
        <title>GuestBook entries</title>
        <table border="1">
            <xsl:for-each select="guestbook/guest">
                        <em><xsl:value-of select="name"/></em>
                        <xsl:value-of select="email"/>
                        <xsl:value-of select="homepage"/>
                        <xsl:value-of select="location"/>
               <xsl:value-of select="comment"/>
               <xsl:value-of select="date"/>

We add a view.aspx page and to that we drag a XML control from the tool box. Right click on the XML control and set the two properties as follows:

  • DocumentSource-> guestbook.xml
  • TransformSource-> gb.xsl

Note: You need to give write permissions to your guestbook.xml page, otherwise it will throw an error. Error trapping and validation should be added as required.

Finally, when you bring up view.aspx page, you will see the following:


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Technical Writer Hodentek
United States United States
Worked in the area of electrical discharges, high energy lasers, high voltage technology, plasma technology, lithography, thin film plastics, superconducting thin films, diamond thin films, electron accelerators, and free electron lasers for several years. Mentored/guided MS and PhD students at several universities in USA, Brazil, Australia, and India.
Reading books and photography are my hobbies.

Also trained workforce clients with legacy computer skills in web related technologies.

I recently authored a beginner level book on MS SQL Server Integration Services. Details available at the following link:

My second book was released in 2008
Learn SQL Server Reporting Services 2008

Get book details at the following site:

This is for anyone who is interested in Reporting Services a la Microsoft. It has over 50 hands-on exercises and covers all aspects of Reporting Services.

Recent new books:

Microsoft SQL Azure Enterprise Application Development 2010
-A Comprehensive book on SQL Azure

Microsoft Visual Studio LightSwitch Business Application Development 2011
A step-by-step approach that is sure to work

Learning SQL Server Reporting Services 2012 Packt Publishers, ISBN: 978-1-84968-992-2 , 2013

You may also be interested in...

Comments and Discussions

Generalu Pin
babu175-May-06 4:47
memberbabu175-May-06 4:47 
Generalgreat article Pin
Guinevere Smith22-Sep-05 21:11
sussGuinevere Smith22-Sep-05 21:11 
GeneralAn article Pin
Danelkits8-Jan-15 1:06
memberDanelkits8-Jan-15 1:06 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 9 Aug 2004
Article Copyright 2004 by mysorian
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid