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]:
- Homepage (URL)
- 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">
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">
<asp:TextBox id="TextBoxHomepageTitle" runat="server">
<asp:TextBox id="TextBoxHomepageURL" runat="server">
<asp:TextBox id="TextBoxLocation" runat="server">
<asp:TextBox id="TextBoxComments" runat="server">
<asp:CheckBox id="CheckBoxPrivate" runat="server">
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.
<homepage url="www.frost.com">David Frost News</homepage>
<date>Friday, July 30, 2004 - 5:02:33 PM</date>
<comment>test this one</comment>
<date>Monday, July 26, 2004 - 5:11:12 PM</date>
<location>137 Tennyson Drive</location>
<date>Thursday, July 23, 2004 -02:52 PM</date>
When the submit button is clicked, the following code will be executed in order:
XMLDocument 'Guestbook.xml' will be loaded.
Dim xdoc As New XmlDocument
- The checkbox entry will be retrieved and set to a text value.
Dim prev As String
If (CheckBoxPrivate.Checked) Then
prev = "yes"
prev = "no"
- 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")
- A new 'Guest' will be prepended to this file via:
- To add the other entries, a
addTextElement function will be used, that takes,
XmlDocument as a constant,
- the element as a constant,
- the name of the element, and
- the location on the form from where it is retrieved.
- 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 _
Dim nodeElem = doc1.CreateElement(strTag)
Dim nodeText = doc1.CreateTextNode(strVal)
- Add the other fields, "
addTextElement(xdoc, elem, "name", TextBoxName.Text)
addTextElement(xdoc, elem, "email", TextBoxEMail.Text)
addTextElement(xdoc, elem, "homepage", TextBoxHomepageTitle.Text)
- 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
- We add two other fields, namely, "
addTextElement(xdoc, elem, "location", TextBoxLocation.Text)
addTextElement(xdoc, elem, "comment", TextBoxComments.Text)
- 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)
- 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.
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:
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:
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