The things I learnt while I migrated from classic asp to asp.net is given here for my reference as well as for new beginners.

PHONE BOOK PROGRAM CODE IN ASP.NET CSHARP

A COMPLETE PROGRAM CODE IN ASP.NET CSHARP FOR PHONE BOOK APPLICATION

This code was tested ok. Simply copy these three files in a folder and run it and you will get the output as shown below.

 

Code for phonebook.xml
<?xml version="1.0" encoding="utf-8"?>
<guestbook>
<record>
<name>raja</name>
<email>raja@roja.com</email>
<mobile>99688888</mobile>
</record>
<record>
<name>roja</name>
<email>roaja@pooja.com</email>
<mobile>9968996877</mobile>
</record>
</guestbook>
Code for phonebook.aspx
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" CodeFile="phonebook.aspx.cs" Inherits="phonebook" %>
<!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>Phone Book</title>
</head>
<body>
<form id="form1" runat="server">
<table border="1" bgcolor="#f0f0f0">
<tr>
<td style="width: 100px">
Name:</td>
<td style="width: 100px">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Email:</td>
<td style="width: 100px">
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Mobile:</td>
<td style="width: 100px">
<asp:TextBox ID="txtMobile" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></td>
</tr>
</table>

<br />
<asp:DataList ID="PhoneBook" Runat="server" Width="100%">
<ItemTemplate>

Name: <%# DataBinder.Eval(Container.DataItem, "name") %><br />
E-mail: <a href="mailto:<%# DataBinder.Eval(Container.DataItem, "email") %>"><%# DataBinder.Eval(Container.DataItem, "email") %></a><br />
Mobile: <%# DataBinder.Eval(Container.DataItem, "mobile") %>
<br />*****************************************<br />
</ItemTemplate>
</asp:DataList>
</form>
</body>
</html>


Code for phonebook.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

public partial class phonebook : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}

protected void Button1_Click(object sender, EventArgs e)
{
// Open the XML doc
System.Xml.XmlDocument myXmlDocument = new System.Xml.XmlDocument();
myXmlDocument.Load(Server.MapPath("guestbook.xml"));
System.Xml.XmlNode myXmlNode = myXmlDocument.DocumentElement.FirstChild;

// Create new XML element and populate its attributes
System.Xml.XmlElement myXmlElement = myXmlDocument.CreateElement("entry");
myXmlElement.SetAttribute("name", Server.HtmlEncode(txtName.Text));
myXmlElement.SetAttribute("email", Server.HtmlEncode(txtEmail.Text));
myXmlElement.SetAttribute("location", Server.HtmlEncode(txtMobile.Text));

// Insert data into the XML doc and save
myXmlDocument.DocumentElement.InsertBefore(myXmlElement, myXmlNode);
myXmlDocument.Save(Server.MapPath("guestbook.xml"));

// Re-bind data since the doc has been added to
BindData();
}

void BindData()
{
XmlTextReader myXmlReader = new XmlTextReader(Server.MapPath("phonebook.xml"));
DataSet myDataSet = new DataSet();
myDataSet.ReadXml(myXmlReader);
myXmlReader.Close();

PhoneBook.DataSource = myDataSet.Tables[0];
PhoneBook.DataBind();
}
}

Thanks for Your Visit

Google Search
Disclaimer and Copy Right