Copied to clipboard

Flag this post as spam?

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


  • Aximili 177 posts 278 karma points
    Apr 27, 2012 @ 03:01
    Aximili
    0

    Updating property value on Save

    When I update a property value on Document.AfterSave, the change is not immediately visible on the screen? Anyone know how to update the screen as well?

    eg. I have this code to remove domain name from links.

    Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
    private void Document_AfterSave(Document sender, SaveEventArgs e)
    {
      string httpDomain = "http://" + HttpContext.Current.Request.Url.Host + "/";
      foreach (Property p in sender.GenericProperties)
      {
        p.Value = p.Value.ToString().Replace(httpDomain, "/").Trim(); // Updated but not visible immediately
      }
    }

    After clicking Save, it's still showing the old value. You have to refresh the page to see the new value.

    How do you force Umbraco to update the screen after you change the value?

    Thankyou in advance.

  • Aximili 177 posts 278 karma points
    May 02, 2012 @ 02:36
    Aximili
    0

    Anyone knows? Is it even possible?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    May 02, 2012 @ 12:46
    Jeroen Breuer
    1

    If you go to the media section and you upload an Image the label properties (for example size) get updated immediately. Don't know if it's using an event, but it might be good to have a look at the source code to see how that works. This is a pretty new feature so it's best to check the source of one of the latest Umbraco versions.

    Jeroen

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 02, 2012 @ 14:29
    Tom Fulton
    2

    It's not possible without some extra steps, the textbox still retains its old value before the postback.  I think the labels in the Media section are updated by the Upload datatype which saves the properties to the DB in addition to using something like Page.FindControl to update the displayed values.  Maybe something like that will work for you.  Or maybe you could use a custom datatype and play with the events to populate its value.

    Also, why not use a content picker instead if you're just linking to pages in the same site?  If you also want to give hte ability to have an external URL you can use the Url Picker datatype from uComponents, which allows the user to choose between picking content/media or entering a URL.

    -Tom

  • Aximili 177 posts 278 karma points
    May 03, 2012 @ 01:39
    Aximili
    0

    Thank you Jeroen and Tom!

    I wasn't aware about UrlPicker, will look at that, thanks!

    EDIT: UrlPicker doesn't strip domain name either so I'll have to do the same thing lol. The user may want to paste URLs like this
    http://domain.com/shop.aspx?id=2301
    so Content picker doesn't work in this case

  • Aximili 177 posts 278 karma points
    Nov 15, 2013 @ 06:02
    Aximili
    0

    This no longer works on Umbraco 6?
    I can no longer change property values on Save??

    This line is executed but seems to do nothing

    p.Value = p.Value.ToString().Replace(httpDomain,"/").Trim();

    EDIT: I now have to use ContentService, it is now a lot harder to set a property value. The above line becomes:

    SetPropertyValue(doc, p, p.Value.ToString().Replace(httpDomain, "/").Trim());

    private static void SetPropertyValue(Document doc, umbraco.cms.businesslogic.property.Property p, object newValue)
    {
      var cs = ApplicationContext.Current.Services.ContentService;
      var csDoc = cs.GetById(Convert.ToInt32(doc.Id));
      csDoc.SetValue(p.PropertyType.Alias, newValue);
      cs.Save(csDoc);
    }

    If I miss anything, please let me know.


Please Sign in or register to post replies

Write your reply to:

Draft