Copied to clipboard

Flag this post as spam?

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


  • Emil Christiansen 66 posts 148 karma points
    Feb 26, 2014 @ 09:09
    Emil Christiansen
    0

    Updating usercontrol datatype on save event

    Hi All!

    This issue might be very simple to solve, but i simply cannot figure out how.

    I have an ultra simple datatype: The only thing it does is extracting the name of the person which last edited the current node and puts the name in a label.

    I have made a new datatype - LastEdited which uses the 'Umbraco Usercontrol Wrapper' and of course the simple usercontrol i have implemented.

    I have then added the LastEdited datatype on one of my document types on the 'Genereic Properties' tab.

    The problem is that the LastEdited datatype is not updated instantly when i save and publish the node. I have to click on another node and click back to the first one before the datatype is updated.

    Does anybody have a work around for this one. Could imagine that this problem is a 'classic' and many of you out there must have had the same issue - but i have not found anything helpfull searching on our and google.

    Thanks in advance!

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Feb 26, 2014 @ 09:14
    Anders Bjerner
    0

    Normally you would have a method for when the control is initialized (this is probably what you have now) but also another method for when the control/datatype is being saved.

    If you have some code to show, we can work on it from there ;)

  • Emil Christiansen 66 posts 148 karma points
    Feb 26, 2014 @ 09:19
    Emil Christiansen
    0

    Hi Anders

    This is the code

        public partial class LastEdited : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack != true)
            {
                string nodeid = Request.QueryString["id"];
                Node currentNode = new Node(Convert.ToInt32(nodeid));
                Label1.Text = "Denne node er sidst redigeret af: " + currentNode.WriterName;
            }
        }
    
        public string umbracoValue;
    
        public object value
        {
            get
            {
                return umbracoValue;
            }
            set
            {
                umbracoValue = value.ToString();
            }
        }
    }
    

    Thanks!

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Feb 26, 2014 @ 09:23
    Anders Bjerner
    0

    I don't think I have used the IUsercontrolDataEditor before, but right now you only update your label if the page is not requested with a postback. Since saving the page triggers a postback, removing your if-statement should solve your problem ;)

  • Emil Christiansen 66 posts 148 karma points
    Feb 26, 2014 @ 09:26
    Emil Christiansen
    0

    I have tried without the postback check also - it doesn't change anything.

  • Mads Krohn 211 posts 504 karma points c-trib
    Feb 26, 2014 @ 09:55
    Mads Krohn
    100

    Hi Emil

    First of all, you should probably use Document or the new Content api depending on the Umbraco version. Using Node, you will only get info from the last published version, right?

    Anyways, did a quick test. I'm not entirely sure what is happening where, but it appears to be a matter of getting the data later in the page event cycle, good old WebForms.

    public partial class LastEditedTest : UserControl, IUsercontrolDataEditor
    {
        protected override void OnPreRender(EventArgs e)
        {
            var nodeid = Request.QueryString["id"];
            var currentDocument = new Document(Convert.ToInt32(nodeid));
            LastEditedLabel.Text = "Denne node er sidst redigeret af: " + currentDocument.Writer.Name;
    
            base.OnPreRender(e);
        }
    
        public object value { get; set; }
    }
    

    This works on my machine at least :)

    Cheers
    Mads

Please Sign in or register to post replies

Write your reply to:

Draft