Get / set user-defined object to profile : Introduction « Profile « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » Profile » Introduction 
15. 5. 3. Get / set user-defined object to profile
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ComplexTypes" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td style="width: 99px">
                    Name:</td>
                <td>
                    <asp:TextBox ID="txtName" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 99px">
                    Street:</td>
                <td>
                    <asp:TextBox ID="txtStreet" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 99px">
                    City:</td>
                <td>
                    <asp:TextBox ID="txtCity" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 99px">
                    Zip Code:</td>
                <td>
                    <asp:TextBox ID="txtZip" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 99px">
                    State:</td>
                <td>
                    <asp:TextBox ID="txtState" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 99px">
                    Country:</td>
                <td>
                    <asp:TextBox ID="txtCountry" runat="server" ></asp:TextBox></td>
            </tr>
        </table>
    
    </div>
        <br />
        <asp:Button ID="cmdGet" runat="server" OnClick="cmdGet_Click" Text="Get" />
        <asp:Button ID="cmdSave" runat="server" OnClick="cmdSave_Click" Text="Save" />
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 ComplexTypes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
      LoadProfile();
    }
  protected void cmdSave_Click(object sender, EventArgs e)
  {
    Profile.Address = new Address(txtName.Text, txtStreet.Text, txtCity.Text, txtZip.Text, txtState.Text, txtCountry.Text);
  }
  protected void cmdGet_Click(object sender, EventArgs e)
  {
    LoadProfile();
  }

  private void LoadProfile()
  {
    txtName.Text = Profile.Address.Name;
    txtStreet.Text = Profile.Address.Street;
    txtCity.Text = Profile.Address.City;
    txtZip.Text = Profile.Address.ZipCode;
    txtState.Text = Profile.Address.State;
    txtCountry.Text = Profile.Address.Country;
  }
}

[Serializable()]
 class Address
{
  private string name;
  public string Name
  {
    get return name; }
    set name = value; }
  }

  private string street;
  public string Street
  {
    get return street; }
    set street = value; }
  }

  private string city;
  public string City
  {
    get return city; }
    set city = value; }
  }

  private string zipCode;
  public string ZipCode
  {
    get return zipCode; }
    set zipCode = value; }
  }

  private string state;
  public string State
  {
    get return state; }
    set state = value; }
  }

  private string country;
  public string Country
  {
    get return country; }
    set country = value; }
  }

  public Address(string name, string street, string city,
    string zipCode, string state, string country)
  {
    Name = name;
    Street = street;
    City = city;
    ZipCode = zipCode;
    State = state;
    Country = country;
  }

  public Address() { }
}
File: Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <profile>
      <properties>
        <add name="address" type="Address" serializeAs="Binary"/>

      </properties>
    </profile>
  </system.web>
</configuration>
15. 5. Introduction
15. 5. 1. Using Profiles
15. 5. 2. Get / set profile data defined in Web.config
15. 5. 3. Get / set user-defined object to profile
15. 5. 4. Inheriting a Profile from a Custom Class
15. 5. 5. Creating Complex Profile Properties
15. 5. 6. Making Personalization Properties Read-Only
15. 5. 7. Defining default values for personalization properties
15. 5. 8. Working with the automaticSaveEnabled attribute
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.