Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Gauge for SharePoint
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » Profile Object in ASP.NET 2.0: Part II

Profile Object in ASP.NET 2.0: Part II

This article shows how a website remembers our last updated information.

Author Rank :
Page Views : 7898
Downloads : 130
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
ProfileConcept.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

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.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Rahul Kumar Saxena
Rahul shows great interests in working with Microsoft technologies. He specializes in the implementation of DataBase & Graphics. His area of expertise includes: C#, ASP.NET,ADO.NET,Windows Forms & Web Services. He hails from background , Master's in Computer Application. With programming he loves photography, traveling and reading books.
(Talabpur*)
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
how the system know by Dhiren On November 8, 2007
Hi Rahhul, I am new to ASP.NEt. But how the system know about the profile of the user? The system knows on the basis of cookies or IP address of the user ? I got that he will create anonymous profile but on the basis of what ?
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.