I'm trying to load a DataTypeDefinition in the frontend (just need to display an Umbraco DropDown), but the values of the control are always the default values. Even after I change the value in the DropDownList and I press the save button the controls get it's old value back. Does someone know what I'm doing wrong?
public partial class Profile : BaseUserControl
{
public dropdown _umbracoDropDown;
#region Properties
/// <summary>
/// Return the MemberId stored in the ViewState. This property must first be set.
/// </summary>
private int MemberId
{
get
{
return Convert.ToInt32(ViewState["MemberId"]);
}
set
{
ViewState["MemberId"] = value;
}
}
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Get the function datatype and add it to the PlaceHolder.
DataTypeDefinition functionDataType = DataTypeDefinition.GetDataTypeDefinition(Configuration.FunctionDataType);
_umbracoDropDown = (umbraco.editorControls.dropdown)functionDataType.DataType.DataEditor;
PlaceHolderFunction.Controls.Add(_umbracoDropDown);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Get the current member his profile.
MemberProfile memberProfile = ControllerLayer.GetMemberProfile();
//Store the MemberId in the ViewState.
MemberId = memberProfile.MemberId;
//Set the normal properties.
TxtName.Text = memberProfile.MemberName;
//Set the properties.
_umbracoDropDown.ID = "DdlFunction";
_umbracoDropDown.CssClass = "dropdown";
SetSelectedListItem(_umbracoDropDown, memberProfile.Function);
}
}
/// <summary>
/// Update the profile of a member.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LnkSave_Click(object sender, EventArgs e)
{
//Create a new MemberProfile-object with the values from this page.
//In here _umbracoDropDown.SelectedValue should be the value the user selected, but it's always the default value.
MemberProfile memberProfile = new MemberProfile(MemberId, TxtName.Text, _umbracoDropDown.SelectedValue);
//Update the profile.
ControllerLayer.UpdateMemberProfile(memberProfile);
}
}
I got it fixed :). In the Page_Load event I set the ID of the dropdownlist, but I don't set it after the postback. Removing the line (not setting an ID) solved the problem :).
Empty control values in frontend
Hello,
I'm trying to load a DataTypeDefinition in the frontend (just need to display an Umbraco DropDown), but the values of the control are always the default values. Even after I change the value in the DropDownList and I press the save button the controls get it's old value back. Does someone know what I'm doing wrong?
Here is my code:
FrontPage:
Code behind:
I hope someone can help me.
I got it fixed :). In the Page_Load event I set the ID of the dropdownlist, but I don't set it after the postback. Removing the line (not setting an ID) solved the problem :).
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.