الأربعاء، 21 ديسمبر 2011

Understand ASP.NET Profile with example

Understanding Profiles
ASP.NET’s default profile functions store visitors’ information in a SQL Server 2005 / 2008 database. The great bonus is that you don’t have to know anything about database structure, stored procedures, data types, or even SQL syntax. Almost everything you need for keeping individual data is pre-built and waiting for you to switch on and configure. This technique—called personalization

Example
We have two web pages, the first web page called Default.aspx and the second web page called setting.aspx.




First Page

Second Page


And here’s the configuration of DropDownList




Configure web.config file as the following




Code in first page (Default.aspx)
  protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            Label1.Text = Profile.FullName;
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = Profile.MyTheme;
    }


Code in Second page (Setting.aspx)
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Label1.Text = Profile.FullName;
            //this command make update to themes to change color to not store the old values.
            DropDownList1.Items.FindByValue(Profile.MyTheme).Selected = true;
        }
    }
    protected void btnSaveProfile_Click(object sender, EventArgs e)
    {
        Profile.FullName = TextBox1.Text;
        Profile.MyTheme = DropDownList1.SelectedValue;
        Response.Redirect("~/Default.aspx");
    }

1 التعليقات:

المبرمج : عمر فتحى سيد يقول...

رائع بس ياريت تعملنا المثال بتاع

Routing in MVC OR ASP.NET
علشان نطبقة

شكرا عمر فتحى