Profile Expression : Profile « Development « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » Development » Profile 
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.