Answered by:
Call Javascript function SPEvenetReceiver

Question
-
Hi All ,
I have sharepoint event recevier and it is working sucessfully , I want to know if there is any way to call a java script function form eventreceviers .
Regards
Srujan.N
srujan
Monday, April 9, 2012 10:43 PM
Answers
-
Hi Srujan
It's not possible to run javascript on event handler as they don’t run in HTTP Context. However, we could have a work around on it. Here I will offer you some ideas for your reference.1. Make use of the redirect of event handler. Custom a web application page and write your javascript into the Page_Load method, then deploy an event handler and register it . Here is an sample code.
class DemoEventHandler : SPItemEventReceiver { HttpContext current; public DemoEventHandler() { current = HttpContext.Current; } public override void ItemDeleting(SPItemEventProperties properties) { SPUtility.Redirect("http://porter:1130", SPRedirectFlags.Trusted, current); } }
2. Customize pure javascript event handler. Here is an useful article for your reference.
http://kiran-kakanur.blogspot.com/2010/02/using-javascript-event-handlers-in.html3. Customize your webpart with usercontrol, and call your javascript by Itemdeleting event of it.
Hope this could help you and feel free to let me know if you have any problem.
For more information, please refer to the following link:
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/00dff9cf-5a82-46f0-a3c9-2e26a4bc3800/
Thanks,
Lhan Han
Wednesday, April 11, 2012 9:57 AM
All replies
-
It may not be possible within the event receivers, because it does not run within HTTP context i think.
Kathir
- Proposed as answer by Muralidharan Palani Tuesday, April 10, 2012 8:10 AM
Tuesday, April 10, 2012 2:38 AM -
Hi Srujan
It's not possible to run javascript on event handler as they don’t run in HTTP Context. However, we could have a work around on it. Here I will offer you some ideas for your reference.1. Make use of the redirect of event handler. Custom a web application page and write your javascript into the Page_Load method, then deploy an event handler and register it . Here is an sample code.
class DemoEventHandler : SPItemEventReceiver { HttpContext current; public DemoEventHandler() { current = HttpContext.Current; } public override void ItemDeleting(SPItemEventProperties properties) { SPUtility.Redirect("http://porter:1130", SPRedirectFlags.Trusted, current); } }
2. Customize pure javascript event handler. Here is an useful article for your reference.
http://kiran-kakanur.blogspot.com/2010/02/using-javascript-event-handlers-in.html3. Customize your webpart with usercontrol, and call your javascript by Itemdeleting event of it.
Hope this could help you and feel free to let me know if you have any problem.
For more information, please refer to the following link:
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/00dff9cf-5a82-46f0-a3c9-2e26a4bc3800/
Thanks,
Lhan Han
Wednesday, April 11, 2012 9:57 AM