In this article I am going to explain more about Profile object. In my previous article about Profiles, I explained that we can not use Profile object directly like as session or cookies. To use Profile object we have to register database. See my previous article of Profile to see how to register the database.
How site, remember my information which I changed? This is done by Profile.
The Profile provider in ASP.NET stores and retrieves information about our site' users. The default profile provider keeps data in SQL Server tables.
For this we have to do some changes in web.config file.
web.config
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings>
<add name="ConnectionString" connectionString="Server=localhost;Database=MergeTable;Uid=sa; pwd="/>
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true"/>
<trust level="High"/>
<profile defaultProvider="MyProfileProvider" >
<providers>
<add name="MyProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ConnectionString" />
</providers>
<properties>
<add name="Name" allowAnonymous="true" />
<add name="City" allowAnonymous="true" />
<add name="Country" allowAnonymous="true" />
<add name="ID" allowAnonymous="true" type="System.Int32" />
</properties>
</profile>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
The default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Profile Concept</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="0" cellspacing="0" width="72%" border="4" align="center">
<tr><td align="center"><table>
<tr><td align="center">
<asp:Label ID="lblMyInformation" runat="server" Text="My Information" Font-Bold="true" Font-Size="14pt">
</asp:Label>
</td></tr>
<tr><td align="center">
<asp:Label ID="lnblId" runat="server" Text="ID" Font-Bold="true" Width="100px"> </asp:Label>
<asp:TextBox ID="txtId" runat="server"> </asp:TextBox>
</td></tr>
<tr><td height="5px"></td></tr>
<tr><td align="center">
<asp:Label ID="lblName" runat="server" Text="Name" Font-Bold="true" Width="100px"> </asp:Label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td></tr>
<tr><td height="5px"></td></tr>
<tr><td align="center">
<asp:Label ID="lblCity" runat="server" Text="City" Font-Bold="true" Width="100px"> </asp:Label>
<asp:TextBox ID="txtCity" runat="server"> </asp:TextBox>
</td></tr>
<tr><td height="5px"></td></tr>
<tr><td align="center" >
<asp:Label ID="lblCountry" runat="server" Text="Country" Font-Bold="true" Width="100px"> </asp:Label>
<asp:TextBox ID="txtCountry" runat="server"> </asp:TextBox>
</td></tr>
<tr><td height="5px"></td></tr>
<tr><td align="center">
<asp:Button ID="btnProfile" OnClick="MyProfile_Click" Text="Information Chnaged" runat="server" />
</td></tr>
</table></td></tr>
</table>
</div>
</form>
</body>
</html>
The Default.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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// With this code the last information will show
if (!IsPostBack)
{
txtName.Text = Profile.Name;
txtCity.Text = Profile.City;
txtCountry.Text = Profile.Country;
txtId.Text = Profile.ID.ToString();
}
}
protected void MyProfile_Click(object sender, EventArgs e)
{
//With this code the user can chnage the information
Profile.Name=txtName.Text;
Profile.City = txtCity.Text;
Profile.Country = txtCountry.Text;
Profile.ID = Int32.Parse(txtId.Text);
}
}
When user run the application then the window will look like this:

Figure 1: When user run the application for first time.

Figure 2: When user fills the information and click on Information Changed Button and close the window.
When user run the application again.

Figure 3: Last saved information appears.
If user change the information again.

Figure 4: User change the information and close the window.
If user run the application again.

Figure 5: Last saved information comes.