Copied to clipboard

Flag this post as spam?

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


  • xrisdoc 54 posts 102 karma points
    Apr 25, 2013 @ 19:12
    xrisdoc
    0

    Custom Data Type value not saving

    Hello,

    I have created a Custom Data Type similar to the one outlined at http://oshyn.com/_blog/Web_Content_Management/post/Custom_DataTypes_in_Umbraco/.

    I have implemented this successfuly on a property on one of my DocumentTypes and the data saves to the database. However, when I implement this on a property on a MemberType it doesn't seem to save this value, when the member is saved.

    Is there something I am missing for implementing this for use with a MemberType?

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CompanySelector.ascx.cs" Inherits="Xris.Umbraco.Web.UserControls.CompanySelector" %>
    <div>
        <asp:DropDownList ID="ddlCompanyID" runat="server" />
    </div>

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Xris.Umbraco.Data;
    namespace Xris.Umbraco.Web.UserControls
    {
        public partial class CompanySelector : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
        {
            public string umbracoValue;
            public object value
            {
                get { return umbracoValue; }
                set { umbracoValue = value.ToString(); }
            }
            protected void Page_Init(object sender, EventArgs e)
            {
                List<MemberCompany> companies = MemberCompany.GetList().OrderBy(c => c.Name).ToList();
                ddlCompanyID.Items.Add(new ListItem("-- Select a Company --", ""));
                foreach (MemberCompany company in companies)
                {
                    ddlCompanyID.Items.Add(new ListItem(company.Name, company.CompanyID.ToString()));
                }
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                if (Page.IsPostBack)
                {
                    int selectedCompanyID = Int32.TryParse(ddlCompanyID.SelectedValue, out selectedCompanyID) ? selectedCompanyID : 0;
                    if (MemberCompany.ExistsInDatabase(selectedCompanyID))
                    {
                        umbracoValue = selectedCompanyID.ToString();
                    }
                }
                LoadValue();
            }
            private void LoadValue()
            {
                if (umbracoValue != null) ddlCompanyID.SelectedValue = umbracoValue.ToString();
            }
        }
    }

     

     

  • xrisdoc 54 posts 102 karma points
    Apr 26, 2013 @ 11:01
    xrisdoc
    0

    It would seem that when the DataType is being used as a property on the MemberType, the SelectedValue on ddlCompanyID is not being maintained on postback for some reason. Yet, as mentioned, it does when used on a DocumentType.

    I have managed to work arround this by obtaining the submitted value of ddlCompanyID using the Request object. I have modified the Page_Load function to the following:

    protected void Page_Load(object sender, EventArgs e)
    {
    if (Page.IsPostBack)
    {
            int selectedCompanyID = 0;
            if (Request[ddlCompanyID.UniqueID] != null)
            selectedCompanyID = Int32.TryParse(Request[ddlCompanyID.UniqueID].ToString(), out selectedCompanyID) ? selectedCompanyID : 0;
                    
            if (MemberCompany.ExistsInDatabase(selectedCompanyID))
            umbracoValue = selectedCompanyID.ToString();
    }

    LoadValue(); }

     

  • 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