Computer Programming: Change Profile Value at runtime in with example

January 12, 2014 0 Comments

We already discussed about create profile for authenticated/anonymous user. This article will cover, Disable profile and save it either automatic or manually in If you want to save profile in, follow some steps
Step-1: Add this code in web.config file
      <authentication mode="Windows" />
      <profile automaticSaveEnabled="false" >
          <add name="DOB" />          
        <compilation debug="false" targetFramework="4.0" />

Step-2: Add a web form into your project.
Step-3: First manually save some string into Profile property on Page_Load() method. Programmer can also use method.

Profile.DOB = "19/april/1986";

Step-4: Add  a TextBox, Button and a label Control to the Design window.
Step-5: Change Profile Property using TextBox at runtime

Default.aspx page 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
        Profile.DOB = TextBox1.Text;
        Label1.Text = "Update DOB is :" + Profile.DOB;

    protected void Page_Load(object sender, EventArgs e)
        if (!Page .IsPostBack )
            Profile.DOB = "19/april/1986";
            Label1.Text = "Your DOB is:" + Profile.DOB;

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    Profile Data :
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        Enter DOB :
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
Code generate the following output

Computer Programming : How to save profile in
Computer Programming : Before changing the profile data

After change at runtime, Code generate the following output

Computer Programming : After changing the profile data

Computer Programming:  After change profile data

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google