Help Required- List Events
Hi I'm writing an event to User Information List...
Here I'm using some conditions. If they are not met then I have show up an error message and stop the event to complete
in the below code I'm using the ItemUpdated Event of the list. In custom code a condition is checked if satisfies then error page should come....
publicoverridevoid ItemUpdated(SPItemEventProperties properties)
{
CustomCode(properties);
}
void CustomCode(SPItemEventProperties properties)
{
if (alreadyExist) {
alreadyExist =
false; properties.ErrorMessage =
"error message"; properties.Cancel =
true;}
Now when I run the above code this message is not coming.....my code is working but it is not opening any error page it directs the user to User Information List......
Please Help...
Thanks
Manu
[1531 byte] By [
Manuk] at [2007-12-30]
Manu,
The "ItemUpdated" event is asynchronous - meaning it traps the event after it happened (thats why it's called "updated").
To do what you want, you have to override "ItemUpdating" which is syncronous.
Happy to help!
Hi
thanks for the advice...but...
I have already tried with Updating event....but the problem is.....the event is attached on my custom list and that custom list has custom fields....
noe in the event I'm checking for the value of those fields....in Updating event....the values are not the the ones which I need to check they are those which were last saved...
any workaround for this?
Thanks
Manu
Yes!
Notice that you have BeforeProperties and AfterProperties - these show you the properties before the change and after the change. so you should check these collections instead of checking the item itself.
ItemUpdating(SPItemEventProperties properties)
{
string newTitle = properties.AfterProperties["Title"];
}
Hi Ishai,
I was able to do this using afterproperties in Updating event...but the adding event was giving null values for the Adding Event...
Am I doing something wrong?
Thanks
Manu
If you read my blog (or search google for itemadding) you will find that this is one of the things that really annoyed me in the last year.
I talked to microsoft, and it's by design - you cant get item properties or access the item in ItemAdding. it's because the item does not exist yet.
Hi Ishai read your blog....
Also added my comment there.....
So what I have thought now is that when user is adding something I will use the "ItemAdded" Event to check that it is valid entry.....as this is asynchronous event I can not show Error Page.....Now what I have thought is
I will delete the added item and then show a Message Box
My problem is I can not find Message Box kind of thing in sharepoint...I'm creating a DLL for the Event Handler......Also I have never worked in web scenario ever before. Please Help.
Thanks
Manu
Thanks Ishai,
I have somehow adjusted my code in Updating and updated to achieve what was intended.....:)
Thanks alot for all the cool help u gave to me....hope to be in touch.....thanks
-Manu