Profile Expression : Profile « Development « ASP.Net






Profile Expression


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ProfileExpr" Debug="true"  %>
<%@ Import Namespace="System.Configuration" %>
<!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>Testing Dynamic Expressions</title>
</head>
<body runat="server" bgcolor="<%$ Profile:BackColor %>">
    <form id="form1" runat="server">
    <asp:DropDownList id="List1" runat="server" DataSource="<%$ Profile:Links %>" />
   
    <asp:TextBox runat="server" ID="editorBackColor" />
    <asp:Button runat="server" ID="Button1" Text="Set BackColor" OnClick="Button1_Click" />

    <asp:TextBox runat="server" ID="editorForeColor" />
    <asp:Button runat="server" ID="Button2" Text="Set ForeColor" OnClick="Button2_Click" />

    
    <asp:TextBox runat="server" ID="editorLinks" />
    <asp:Button runat="server" ID="Button3" Text="Add Link" OnClick="Button3_Click" />
    <asp:Button runat="server" ID="Button4" Text="Remove Link" OnClick="Button4_Click" />

    <asp:Button runat="server" ID="Button5" Text="Refresh" backcolor="<%$ Profile:BackColor %>" />

    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ProfileExpr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Profile.BackColor = editorBackColor.Text;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Profile.ForeColor = editorForeColor.Text;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Profile.Links.Add(editorLinks.Text);
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Profile.Links.Remove(editorLinks.Text);
    }
}


File: Web.Config

<configuration>
    <profile enabled="true" defaultProvider="CookieProfileProvider">
      <properties>
        <add name="BackColor" type="string" allowAnonymous="true"/>
        <add name="ForeColor" type="string" allowAnonymous="true"/>
        <add name="Links" type="System.Collections.Specialized.StringCollection" allowAnonymous="true" serializeAs="Xml"/>
      </properties>
      <providers>
        <clear/>
        <add applicationName="/" name="CookieProfileProvider" type="ProAspNet20.Advanced.CS.Components.CookieProfileProvider, ProAspCompLib"/>
      </providers>
    </profile>
</configuration>    

 








Related examples in the same category

1.Demonstrates how to use the ASP.NET user profile
2.Dynamic expression
3.Profile information