locked
refresh sharepoint page after Item Added in event handler RRS feed

  • Question

  • Event handler ItemAdded is working. However, the site does not refresh right away. I am creating some folder structures and moving the item in to that. Also starting workflow based on itemID. Everything works fine..but it doesnot show up the workflow status in my default view when an item is added. . If I refresh (or hit F5) then it shows up with the item. Can anyone suggest how to refresh the page after item added or show up the workflow status once it is added to the library?

    I tried with multiple update options i.e.

    item.list.update();//not working

    web.update();//not working

    On Itemiadding event I see the propertie of listitem is null value..so I could not start the WF on Item Adding event. Any ideas?

    Wednesday, November 3, 2010 3:26 PM

Answers

  • The only way to get it to refresh on the fly is to use the ItemAdding event receiver method.

    When the ItemAdding method is executed, the item is not created yet, so you won't have access to the propertie.ListItem yet as it is going to be null.

    You will have access to the properties.AfterProperties and it should have all the fields that were entered into the new form.

    but beware, as the ID for the new item won't exist yet, so if that is an email that is going to be sent out to the item or something they need related to the ID, is not do-able!

    Regarding workflows; they usually get started after the item is started, so there is no real control over the workflow field status.

    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 6:22 PM sig removed - don't ask people to mark your posts
    • Marked as answer by Porter Wang Thursday, November 11, 2010 5:41 AM
    Wednesday, November 3, 2010 6:11 PM

All replies

  • The only way to get it to refresh on the fly is to use the ItemAdding event receiver method.

    When the ItemAdding method is executed, the item is not created yet, so you won't have access to the propertie.ListItem yet as it is going to be null.

    You will have access to the properties.AfterProperties and it should have all the fields that were entered into the new form.

    but beware, as the ID for the new item won't exist yet, so if that is an email that is going to be sent out to the item or something they need related to the ID, is not do-able!

    Regarding workflows; they usually get started after the item is started, so there is no real control over the workflow field status.

    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 6:22 PM sig removed - don't ask people to mark your posts
    • Marked as answer by Porter Wang Thursday, November 11, 2010 5:41 AM
    Wednesday, November 3, 2010 6:11 PM
  •  

    I know this is old, but did you ever try to change the Synchronous property in the elements.xml for the event?  I changed my ItemAdded to syncronous and I could start seeing my changes to the page immediately.  Before I had to hit F5 because the event reciever was running Async. 

     

    @Dennis, turns out the ItemAdding event is synchronous by default.  This why you see this behaviour on this event but it is not the only way to make the page refresh.


    Lance
    Friday, October 7, 2011 10:31 AM