Copied to clipboard

Flag this post as spam?

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


  • Justin Yoo 16 posts 39 karma points
    Feb 07, 2012 @ 02:26
    Justin Yoo
    0

    Custom DataType using UserControl lose value after postback

    Hi, Guys.

    I'm using Umbraco 4.7.1.1 for the website development. While I was developing a custom data type using the UserControl, I found that, after the postback event, the field data disappeared.

     

    public partial class MemberTypePicker : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
    #region Properties
    public object value { get; set; }
    #endregion
    #region Event Handlers
    protected void Page_Load(object sender, EventArgs e)
    {
    if (this.IsPostBack)
    {
    this.value = this.MemberTypes.Text;
    }
    this.MemberTypes.Text = "Administrator";
    }
    When you guys look at the code above, it is the typical and simple way of creating a custom data type user control. The TextBox control, MemberTypes, is forced to have the "Administrator" value. However, once I click the save button, the MemberTypes.Text lose its value to String.Empty.
    Can anyone let me know what I have missed? I've implemented several custom data type user controls so far, but it's my first time to face this issue.
    Cheers,
    Justin

     

  • Justin Yoo 16 posts 39 karma points
    Feb 07, 2012 @ 02:37
    Justin Yoo
    0

    When I run the debug mode, I could get the result above, there's nothing!

     

     

  • Chris Randle 85 posts 199 karma points c-trib
    Jun 12, 2012 @ 16:28
    Chris Randle
    0

    Hi,

    The way I have handled in the past is to create a class in App_Code that extends from ApplicationBase. Add some events, as follows:

     

     

    public Document Document { get; set; }

     

        public CustomEvents()

    {

            Document.AfterPublish += Document_AfterPublish;

            Document.New += Document_New;

    }

     

        private void Document_AfterPublish(Document document, umbraco.cms.businesslogic.PublishEventArgs e)

        { 

    // check to see if this is the right DocType firing the event, read the property, and persist

     if (document.ContentType.Alias == "MemberTypePicker") documentTitle = document.Text; 

    umbraco.library.UpdateDocumentCache(document.Id);

    }

     

    Essentially, your document has the value when raising the event, and you read it, then save it to Umbraco. Hope this helps.

     

Please Sign in or register to post replies

Write your reply to:

Draft