none
Understanding event receiver behaviour

    Question

  • If I have this code...

    public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdded(properties);
                SPListItem _currentItem = properties.ListItem;
                _currentItem["Title"] = DateTime.Now.ToString();
                _currentItem.Update();
            }

    The item title is changed.

    However if I have the same code in an itemAdding event then nothing happens.

    2 questions:
    Why do I need to refresh the page to see the new title value?
    Why can I not achieve the same thing using itemAdding?

    Thursday, October 17, 2013 2:16 AM

Answers

  • ItemAdding Synchronous action occurred with HttpContext, You can redirect or refresh after finishing event.

    ItemAdded Asynchronous action  occurred with SharePoint Timer. This eventhasn't access to httpcontext.

    Why do I need to refresh the page to see the new title value? This related to asynhronous behavior.

    Why can I not achieve the same thing using itemAdding? May be you not attach to correct event (check deployment feature)or there is another event run after this event

     


    Tarek Yehia

    Thursday, October 17, 2013 4:28 AM

All replies

  • ItemAdding Synchronous action occurred with HttpContext, You can redirect or refresh after finishing event.

    ItemAdded Asynchronous action  occurred with SharePoint Timer. This eventhasn't access to httpcontext.

    Why do I need to refresh the page to see the new title value? This related to asynhronous behavior.

    Why can I not achieve the same thing using itemAdding? May be you not attach to correct event (check deployment feature)or there is another event run after this event

     


    Tarek Yehia

    Thursday, October 17, 2013 4:28 AM
  • Some times you need to do IISRESET to see the event attach feature working. It should work on itemadding.

    Bala

    Thursday, October 17, 2013 4:58 AM