Hello Feras,
There are three things you need to do in order to achieve what you want:
1. Modify the Web.config file to include the new fields.
2. Add the new fields to the controls for editing and creating users.
3. Add the code to save and retrieve the new information to/from the database.
1. Open the Web.config for your project and find this section:
<profile defaultProvider="Sitefinity">
...
<properties>
<add name="FirstName"/>
<add name="LastName"/>
<add name="TestProperty"/>
</properties>
</profile>Include a tag for the field that you want to create, as highlighted.
2. Modify the control that edits the user information. This is
<project directory>/Admin/CmsAdmin/User.aspx. Find the EditTemplate and InsertTemplate tags and modify the code in them as follows:
<fieldset class="userinfo">
<ol>
<li><cc2:FieldLabel ID="lblFirstName" runat="server" Text="First name" TargetID="FirstName"></cc2:FieldLabel><asp:TextBox ID="FirstName" runat="server"></asp:TextBox></li>
<li><cc2:FieldLabel ID="lblLastName" runat="server" Text="Last name" TargetID="LastName"></cc2:FieldLabel><asp:TextBox ID="LastName" runat="server"></asp:TextBox></li>
<li><cc2:FieldLabel ID="lblTestProperty" runat="server" Text="Test Property" TargetID="TestProperty"></cc2:FieldLabel><asp:TextBox ID="TestProperty" runat="server"></asp:TextBox></li>
</ol>
</fieldset>Make sure you change the markup in both templates. They show the newly created field when creating a new user and when editing an existing user. Now the new field will show up in the admin section of your project.
3. However, in order for it to work, you have to add code to save its data in the database. To do this, open the code-behind file (User.aspx.cs) and add the following highlighted code:
private void FillProfileData()
{
...
TextBox textBox = container.FindControl("FirstName") as TextBox;
if (textBox != null)
{
textBox.Text = profile.FirstName;
}
textBox = container.FindControl("LastName") as TextBox;
if (textBox != null)
{
textBox.Text = profile.LastName;
}
textBox = container.FindControl("TestProperty") as TextBox;
if (textBox != null)
{
textBox.Text = profile.TestProperty;
}
}
}
...
private void SaveUserProfile(string username)
{
...
TextBox textBox = container.FindControl("FirstName") as TextBox;
if (textBox != null)
{
profile.FirstName = textBox.Text;
}
textBox = container.FindControl("LastName") as TextBox;
if (textBox != null)
{
profile.LastName = textBox.Text;
}
textBox = container.FindControl("TestProperty") as TextBox;
if (textBox != null)
{
profile.TestProperty = textBox.Text;
}
profile.Save();
}
}With this final step, you should have a new field for every user in your project. Of course, you can name it the way you like.You only need to change "TestProperty" in the above example with your own name.
Regards,
Slavo
the
telerik team