Asp.net profile is either not displaying or saving the data the user enters, However there is No Errors. here is a view of the code below: the webproject just Runs and nothing is displayed on both firstname amd lastname label.
This is A WEB PROJECT ,,, I opened the project using OPEN WEBSITE!
HOWEVER the Project Displays it as "WEBPROJECT.sln(3)" at the program title bar of VISUAL STUDIOS.
This is when the user creates the account and saves the users profile settings: NEW AND UPDATED
protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
{
// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(RegisterUser.UserName, true);
// Save profile - must be done since we explicitly created it
TextBox txtNewFirstName = (TextBox)RegisterUser.FindControl("txtNewFirstName");
Profile.FirstName = txtNewFirstName.Text;
TextBox txtNewLastName = (TextBox)RegisterUser.FindControl("txtNewLastName");
Profile.LastName = txtNewLastName.Text;
p.Save();
}
And this is when its is displayed: NEW AND UPDATED
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);
Label firstName = (Label)LoginView1.FindControl("firstName");
Profile.FirstName = firstName.Text;
Label lastName = (Label)LoginView1.FindControl("lastName");
Profile.LastName = lastName.Text;
}
}
And this is the Web config: NEW AND UPDATED
<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
<properties>
<add name="FirstName" type="String" serializeAs="String"/>
<add name="LastName" type="String" serializeAs="String"/>
<add name="Gender" type="String" serializeAs="String"/>
<add name="BirthDate" type="DateTime" serializeAs="String"/>
<add name="Occupation" type="String" serializeAs="String"/>
<add name="Website" type="String" serializeAs="String"/>
<group name="Forum">
<add name="Posts" type="Int32" defaultValue="0"/>
<add name="AvatarUrl" type="String" serializeAs="String"/>
<add name="Signature" type="String" serializeAs="String"/>
</group>
<group name="Address">
<add name="Street" type="String" serializeAs="String"/>
<add name="PostalCode" type="String" serializeAs="String"/>
<add name="City" type="String" serializeAs="String"/>
<add name="State" type="String" serializeAs="String"/>
<add name="Country" type="String" serializeAs="String"/>
</group>
<group name="Contacts">
<add name="Phone" type="String" serializeAs="String"/>
<add name="Fax" type="String" serializeAs="String"/>
</group>
</properties>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
This is Whats being displayed on the aspnet_Profile on my sql server:
[PropertyNames]
[LastName:S:0:0:FirstName:S:0:0:]
This is redone of the previous code so please ignore previous comments below!
I have also Tryed PreRender Method:
<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);
Label firstName = (Label)LoginView1.FindControl("firstName");
Profile.FirstName = firstName.Text;
Label lastName = (Label)LoginView1.FindControl("lastName");
Profile.LastName = lastName.Text;
}
But i get a error: Object reference not set to an instance of an object. for Profile.FirstName = firstName.Text;
Simplify it by removing all properties from Web.Config except for the first and last name properties. Try to narrow it down.
The following works for me. Although I set anonymousIdentification to true for convenience, I've given you the full syntax for a working membership Web.Config entry: