// if the UserName property contains an emtpy string, retrieve the profile
// for the current user, otherwise for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
public void SaveProfile()
{
// if the UserName property contains an emtpy string, save the current user's profile,
// othwerwise save the profile for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
the selected value will be ignored/"over-written" with the page loads.
For more detail - The page first loads all the controls, then all the default/selected values from the controls on the page. Then the Page_Load method runs, in this case, replacing any default/selected values on the page overwriting default/selected values
from the controls on the page.
So you'll need to change the default value/attribute to "HTML" in the web.config file under the "profile" settings in the "Preferrences" profile group. Let me know if this helps...
Ray Linder
Glacsy | Glacsy.com
raylinder@glacsy.com
I added this : <add name="Newsletter" type="SkiX.SkiStyle.BLL.Newsletters.SubscriptionType" defaultValue="Html" />
But it says that :
The property 'Preferences.Newsletter' could not be created from it's default value. Error message: There is an error in XML document (1, 1).
I have my enum like this :
public
enum
SubscriptionType :
int
{
None = 0,
PlainText = 1,
Html
}
What I don't get is that Html does not need a value ?
I do understand this line : ddlSubscriptions.SelectedValue = profile.Preferences.Newsletter.ToString();
so it gets my default profile, in stead of the selected value from HTML.
Koen
Member
73 Points
49 Posts
Newsletter
Mar 15, 2007 07:36 AM|LINK
Hi,
I want to enable the user profile in that way that a html version of the newsletter is selected by default when registring.
in my userprofile.aspx I have :
<asp:ListItem Text="HTML versie" Value="Html" Selected="true" />
<asp:ListItem Text="Geen abonnement" Value="None" />
<asp:ListItem Text="Plain tekst" Value="PlainText" />
in my enum.cs (in newsletter folder) I have :
public enum SubscriptionType : int
{
None = 0,
PlainText = 1,
Html
}
However, it is still set to None when the new user enters the profile page.
What am I doing wrong ?
Here is my pageload and save function.
Do you see anything ?
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ddlCountries.DataSource = Helpers.GetCountries();
ddlCountries.DataBind();
// if the UserName property contains an emtpy string, retrieve the profile
// for the current user, otherwise for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
ddlSubscriptions.SelectedValue = profile.Preferences.Newsletter.ToString();
ddlLanguages.SelectedValue = profile.Preferences.Culture;
txtFirstName.Text = profile.FirstName;
txtLastName.Text = profile.LastName;
ddlGenders.SelectedValue = profile.Gender;
if (profile.BirthDate != DateTime.MinValue)
txtBirthDate.Text = profile.BirthDate.ToShortDateString();
ddlSkiType.SelectedValue = profile.SkiInfo.Type;
txtWebsite.Text = profile.Website;
txtStreet.Text = profile.Address.Street;
txtCity.Text = profile.Address.City;
txtPostalCode.Text = profile.Address.PostalCode;
txtState.Text = profile.Address.State;
ddlCountries.SelectedValue = profile.Address.Country;
txtPhone.Text = profile.Contacts.Phone;
txtFax.Text = profile.Contacts.Fax;
txtAvatarUrl.Text = profile.Forum.AvatarUrl;
txtSignature.Text = profile.Forum.Signature;
}
}
public void SaveProfile()
{
// if the UserName property contains an emtpy string, save the current user's profile,
// othwerwise save the profile for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
profile.Preferences.Newsletter = (SubscriptionType)Enum.Parse(typeof(SubscriptionType), ddlSubscriptions.SelectedValue);
profile.Preferences.Culture = ddlLanguages.SelectedValue;
profile.FirstName = txtFirstName.Text;
profile.LastName = txtLastName.Text;
profile.Gender = ddlGenders.SelectedValue;
if (txtBirthDate.Text.Trim().Length > 0)
profile.BirthDate = DateTime.Parse(txtBirthDate.Text);
profile.SkiInfo.Type = ddlSkiType.SelectedValue;
profile.Website = txtWebsite.Text;
profile.Address.Street = txtStreet.Text;
profile.Address.City = txtCity.Text;
profile.Address.PostalCode = txtPostalCode.Text;
profile.Address.State = txtState.Text;
profile.Address.Country = ddlCountries.SelectedValue;
profile.Contacts.Phone = txtPhone.Text;
profile.Contacts.Fax = txtFax.Text;
profile.Forum.AvatarUrl = txtAvatarUrl.Text;
profile.Forum.Signature = txtSignature.Text;
profile.Save();
}
tnx
koen
raylinder
Member
79 Points
24 Posts
Re: Newsletter
Apr 03, 2007 11:27 PM|LINK
ddlSubscriptions.SelectedValue = profile.Preferences.Newsletter.ToString();
You may want to check the "default" value in the web.config file under the "profile" preferrences and change is to "HTML"...
When you're calling:
<asp:ListItem Text="HTML versie" Value="Html" Selected="true" />
<asp:ListItem Text="Geen abonnement" Value="None" />
<asp:ListItem Text="Plain tekst" Value="PlainText" />
the selected value will be ignored/"over-written" with the page loads.
For more detail - The page first loads all the controls, then all the default/selected values from the controls on the page. Then the Page_Load method runs, in this case, replacing any default/selected values on the page overwriting default/selected values from the controls on the page.
So you'll need to change the default value/attribute to "HTML" in the web.config file under the "profile" settings in the "Preferrences" profile group. Let me know if this helps...
Glacsy | Glacsy.com
raylinder@glacsy.com
Koen
Member
73 Points
49 Posts
Re: Newsletter
Apr 04, 2007 06:29 AM|LINK
Hi,
I added this : <add name="Newsletter" type="SkiX.SkiStyle.BLL.Newsletters.SubscriptionType" defaultValue="Html" />
But it says that :
The property 'Preferences.Newsletter' could not be created from it's default value. Error message: There is an error in XML document (1, 1).
I have my enum like this :
public
enum SubscriptionType : int{
None = 0,
PlainText = 1,
Html
}
What I don't get is that Html does not need a value ?
I do understand this line : ddlSubscriptions.SelectedValue = profile.Preferences.Newsletter.ToString();
so it gets my default profile, in stead of the selected value from HTML.
Any tips welcome
koen