Manuk

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....

public override void 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



Re: SharePoint - Development and Programming Help Required- List Events

Ishai Sagi

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!






Re: SharePoint - Development and Programming Help Required- List Events

Manuk

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





Re: SharePoint - Development and Programming Help Required- List Events

Ishai Sagi

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"];

}






Re: SharePoint - Development and Programming Help Required- List Events

Manuk

Thankyou Ishai....I will try this out...thanks again



Re: SharePoint - Development and Programming Help Required- List Events

Manuk

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





Re: SharePoint - Development and Programming Help Required- List Events

Ishai Sagi

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.






Re: SharePoint - Development and Programming Help Required- List Events

Manuk

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





Re: SharePoint - Development and Programming Help Required- List Events

Ishai Sagi

Manuk,

  1. Angus (from Microsoft) contacted me yesterday and told me the AfterProperties will be availalbe in ItemAdding, but only for certain types of lists (he could'nt say which), so you may want to check.
  2. Message box is something that shows on the client. In a windows application you can show a message box because there is a user looking at it. An event handler is running on the server. there is no user looking at it - message box will not and should not be possible.
    Remember - asynch handlers like ItemUpdated are happening after the user clicked ok, and have been redirected to another page, and maybe the user even had time to click on another link. When you are in ItemUpdated, there is no user infront of the application.
    My idea was to send an email to the user letting him know.
  3. I have a better solution for you - enable approval on the list. This is in advanced setting of the list. This means that the user writes what he wants, and then another user (maybe the same user) has to approve it for it to be shown.
    By requiring approval, you can put all your code into ItemUpdating - and there you can show an error to the user since it's synchronous. I used that in my solution (luckily we wanted approval proccess anyway)






Re: SharePoint - Development and Programming Help Required- List Events

Manuk

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





Re: SharePoint - Development and Programming Help Required- List Events

GregorioRojas

I can not get my custom ErrorMessage to display on my ItemUpdating event. I can cancel the event but all I get is the generic sharepoint error page.





Re: SharePoint - Development and Programming Help Required- List Events

Nanditab

I m facing the same issue. Were you able to fix this issue





Re: SharePoint - Development and Programming Help Required- List Events

GregorioRojas

No i was not.

sorry