Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 22, 2010 @ 11:48
    Jeroen Breuer
    0

    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:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Profile.ascx.cs" Inherits="MikzIntranet.UmbracoExtension.UserControls.Profile" %>
    <asp:Panel ID="PnlProfile" runat="server" DefaultButton="LnkSave" CssClass="profileContainer">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td class="labelCell"><strong>Naam</strong></td>
                <td class="fieldCell"><asp:TextBox ID="TxtName" runat="server" ValidationGroup="Profile" CssClass="textbox"></asp:TextBox></td>
                <td class="validatorCell"><asp:RequiredFieldValidator ID="ReqValName" runat="server" ControlToValidate="TxtName" ErrorMessage="Voer uw naam in." ValidationGroup="Profile"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td class="labelCell"><strong>Functie</strong></td>
                <td class="fieldCell"><asp:PlaceHolder ID="PlaceHolderFunction" runat="server"></asp:PlaceHolder></td>
                <td class="validatorCell"></td>
            </tr>
            <tr>
                <td class="labelCell">&nbsp;</td>
                <td class="fieldCell"><asp:LinkButton ID="LnkSave" runat="server" Text="Opslaan" OnClick="LnkSave_Click" ValidationGroup="Profile"></asp:LinkButton></td>
                <td class="validatorCell">&nbsp;</td>
            </tr>
        </table>
    </asp:Panel>

    Code behind:

        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 hope someone can help me.

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 22, 2010 @ 12:26
    Jeroen Breuer
    0

    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 :).

  • 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.

Please Sign in or register to post replies