Free guestbook HTML by visual basic source code


This article is written by Pon Saravanan  on 10-Sep-09 Last modified on :17-May-12





Simple Guestbook Html Code with File System

If the website is designed and developed only in plain HTML, it is nearly impossible to create a Guest Book with just plain HTML in server to track the guests. But now a days it is easier to find an ASP hosting for cheaper prices. It should be noted that, the server side execution is required for saving a GuestBook. Though the databases are the way to go. To make the article simpler I have used a flat file for GuestBook. As the target of this article is not providing a full working application for GuestBook, I am just writing some code for beginners to learn how to start with.

Guestbook Html Code To write into File System

As we discussed little earlier, the guest book is going to be saved into the file system. Since the flat file is just a text storage, we need to delimit the data in a proper way. so that later on the data can be presented nicely. There are two segments we need to consider for delimiters, one is for the row delimiter another is a column delimiter. so we will use ~ to differentiate each row. and with in the row we can use | to delimit the columns

Source Code


Guestbook Html Code Markup (*.Aspx)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
    <div style="width: 100%">
        <div style="width: 20%; float: left">
            Name
        </div>
        <div style="width: 80%; float: left">
            <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
        </div>
    </div>
    <div style="width: 100%">
        <div style="width: 20%; float: left">
            E-mail
        </div>
        <div style="width: 80%; float: left">
            <asp:TextBox runat="server" ID="txtEmail"></asp:TextBox>
        </div>
    </div>
    <div style="width: 100%">
        <div style="width: 20%; float: left">
            Comments
        </div>
        <div style="width: 80%; float: left">
            <asp:TextBox runat="server" ID="txtComments" TextMode="MultiLine" Columns="30" Rows="5"></asp:TextBox>
        </div>
    </div>
    special characters not allowed
    <asp:Button runat="server" ID="btnSubmit" Text="Post" />
    </form>
</body>
</html>

Code Behind (*.vb)

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim GuestBookContent = txtName.Text & " | " & _
            txtEmail.Text & " | " & _
            txtComments.Text & " ~ "
       
        My.Computer.FileSystem.WriteAllText(Server.MapPath("~/GuestBook.txt"), GuestBookContent, True)
    End Sub
    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
    End Sub
End Class

Guestbook html code To Parse Text file

The saved GuestBook.Txt can be parsed again using guestbook html code with another one aspx file to load in to the screen by using a Split () function
'~' To delimit a guest entry
'|' To delimit attributes as name email and comments

First split using ‘~’, will get the entire guest book entry for one visitor. Take that entry and parse again using split with |, First element is Name, Second element is e-mail, third element is comments. It can be displayed easily with some HTML formatting.

Source Code

Markup

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="List.aspx.vb" Inherits="ListGuests" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false">
        <Columns>
        <asp:BoundField HeaderText="Name" DataField="GuestName"/>
        <asp:BoundField HeaderText="Email" DataField="Email" />
        <asp:BoundField HeaderText="Content" DataField="Content" HtmlEncode="false" />
        </Columns>
    </asp:GridView>
    </div>
    </form>
</body>
</html>

Code Behind

Imports System.Data
Partial Class ListGuests
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            BindGrid()
        End If
    End Sub
    Private Sub BindGrid()
        Dim GuestBook As New DataTable
        Dim GuestsLogged As String
        Dim GuestBookPath As String = Server.MapPath("~/Guestbook.txt")
        GuestsLogged = My.Computer.FileSystem.ReadAllText(GuestBookPath)
        GuestBook.Columns.Add(New DataColumn("GuestName"))
        GuestBook.Columns.Add(New DataColumn("Email"))
        GuestBook.Columns.Add(New DataColumn("Content"))

        For Each Guest In GuestsLogged.Split("~")
            If (Guest.Split("|").Length > 2) Then
                Dim GuestRow As DataRow = GuestBook.NewRow
                GuestRow("GuestName") = Guest.Split("|")(0)
                GuestRow("Email") = Guest.Split("|")(1)
                GuestRow("Content") = Guest.Split("|")(2).Replace(vbCrLf, "<br />")
                GuestBook.Rows.Add(GuestRow)
            End If
        Next
        GridView1.DataSource = GuestBook
        GridView1.DataBind()
    End Sub
End Class











Comments
  • GUEST
    Hi,
    Really well this article.If possible,release some MOSS articles also.

    By
    Ve.Bala
    9/14/2009 11:32:53 PM

  • GUEST
    Halo!
    Good resource! Thx :]
    10/17/2009 8:24:56 PM

  • GUEST
    Nice 10/20/2009 9:54:28 PM

  • GUEST
    thanks 11/15/2009 1:42:36 PM

  • GUEST
    thanks 2/1/2010 8:56:47 PM

  • GUEST
    thanks from tom 3/5/2010 12:11:43 AM

  • GUEST
    very nice and neat 2/17/2011 10:23:10 PM

  • GUEST
    salammm 2/28/2011 6:40:00 AM

  • GUEST
    aslam 1/14/2012 10:02:52 AM

  • GUEST
    Appreciate it so much for this terrific article.In fact looking forward to read more. Much appreciated. 3/21/2012 1:41:45 AM

  • GUEST
    Thank you so much for this html code 4/9/2012 5:09:25 PM

  • GUEST
    http://www.canhovinhomesnguyentrai.com/
    http://www.canhovinhomesnguyentrai.com/chung-cu-vinhomes-nguyen-trai-smart-city/
    http://www.canhovinhomesnguyentrai.com/lam-sao-de-co-phong-khach-dep-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/doi-net-ve-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/co-nen-mua-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/chon-mua-chung-cu-vinhomes-nguyen-trai-va-3-dieu-toi-ky-theo-phong-thuy/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-noi-tan-huong-cuoc-song-hanh-phuc/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-la-noi-song-ly-tuong-cho-gia-dinh-tre/
    http://www.canhovinhomesnguyentrai.com/thong-tin-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/bung-no-du-an-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-du-an-sieu-do-thi-moi/
    http://www.canhovinhomesnguyentrai.com/tai-sao-ban-nen-mua-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-du-an-chung-cu-cao-cap/
    http://www.canhovinhomesnguyentrai.com/to-hop-sieu-do-thi-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-thanh-pho-moi/
    http://www.canhovinhomesnguyentrai.com/nhung-ly-do-ban-nen-mua-chung-cu-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/can-ho-vinhomes-nguyen-trai-co-dieu-gi-noi-bat/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-la-du-an-dang-mong-doi-nhat-tai-khu-thanh-xuan/
    http://www.canhovinhomesnguyentrai.com/vinhomes-nguyen-trai-tiem-nang-voi-khach-nuoc-ngoai/
    http://www.canhovinhomesnguyentrai.com/4-tieu-chi-lam-nen-su-thanh-cong-cua-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/cuoc-song-hien-dai-tai-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/cac-don-vi-tham-gia-du-an-vinhomes-tran-duy-hung/
    http://www.canhovinhomesnguyentrai.com/gioi-thieu-du-an-vinhomes-nguyen-trai/
    http://www.canhovinhomesnguyentrai.com/mat-bang-vinhomes-nguyen-trai-vinhomes-smart-city/
    http://www.canhovinhomesnguyentrai.com/du-an-chung-cu-vinhomes-metropolis-lieu-giai/
    http://khodadep.com/da-hoa-cuong-cao-cap-40.html
    http://khodadep.com/da-op-lat-granite-50.html
    http://khodadep.com/da-op-bep-granite-51.html
    http://basaopro.com/bat-che-nang/
    http://basaopro.com/cua-luoi-chong-muoi-cua-luoi-chong-con-trung/
    http://basaopro.com/gian-phoi-thong-minh/
    http://basaopro.com/luoi-bao-ho-an-toan/
    http://ketsatcaocap.vn/
    12/16/2016 12:25:57 PM


Comments
   
Captcha Image
For you specially:  
Captcha Text Enter the text in the image.(Not Case sensitive)    



Spam Bot Trap



   



Select Theme
White
Blue
Brown
Gray