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
    Jun 17, 2011 @ 02:49
    Aximili
    0

    Document.AfterSave is not showing the new value

    I have this method

      void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
    if (sender.ContentType.Alias == "News")
    {
    if (sender.getProperty("teaser").Value.ToString() == "")
    {
    sender.getProperty("teaser").Value = Web.GetFirstFewWords(sender.getProperty("bodyText").Value.ToString());
    umbraco.library.UpdateDocumentCache(sender.Id);
    }
    }
    }

    Although the value (ie. teaser) is updated, it is not showing it on the screen, I have to refresh the screen (by reclicking on the Document) to show the new value.

    I tried doing it on BeforeSave, same thing.

    How can I update a value on Save, and have it shown on the screen? Thanks in advance.

  • Mathijs 27 posts 60 karma points
    Jun 17, 2011 @ 20:32
    Mathijs
    0

    Maybe an annoying answer. But why are you using umbraco events to dome some job one would normally do when rendering the actual content to the template using razor or other methods. 

    Mathijs

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 17, 2011 @ 23:09
    Tom Fulton
    0

    I don't think there is any (good) way to show the updated value, since I believe it loads from viewstate.  You could possibly use some javascript or a custom datatype for the teaser field that reloads on each postback.. 

    I do agree with Mathijs though, you should probably just handle this when you are rendering.  If you want the option to override it you could use the teaser textbox value if it's not empty.

  • Aximili 177 posts 278 karma points
    Jun 20, 2011 @ 04:18
    Aximili
    0

    No Mathjis that's a good comment. And thanks Tom. I am new to Umbraco and I don't know how to override the render function. Could you tell me how to do it?

  • Aximili 177 posts 278 karma points
    Jun 23, 2011 @ 04:13
    Aximili
    0

    Anyone else know how to override the render function as Mathjis said....?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 23, 2011 @ 04:35
    Tom Fulton
    0

    Hi Hardi,

    How are you currently displaying the Teaser text on your website?  Via an umbraco:Item tag, or a macro (xslt or razor)?

    If you're using an umbraco:Item tag currently, you'll probably need to use a macro instead so you can call your GetFirstFewWords function.

    If you're using an XSLT macro, you can write a quick XSLT Extension method so that you can call the GetFirstFewWords function from XSLT.  Basically all you have to do is decorate your class with [XsltExtension] - here's a quick article on it.  Then you can call it from XSLT with something like <xsl:value-of select="yourextension:GetFirstFewWords($currentPage/bodyText)"/>.

    If you're using Razor, I can't really help you much :)

    -Tom

  • Aximili 177 posts 278 karma points
    Jun 23, 2011 @ 06:21
    Aximili
    0

    Ah... is that what you guys meant? I can do anything I want on the front end, true.

    But what I wanted is to give the admin a default Teaser which they can then edit. Currently they have to reclick the document on the tree to have the default Teaser displayed.

    Thanks Tom :)

Please Sign in or register to post replies

Write your reply to:

Draft