locked
JavaScript Feedback in SPItemEvents RRS feed

  • Question

  • Is it possible to provide feedback to the user through javascript popup dialog?  For example, if the user attempts to delete a document, and after my custom code runs I find that I don't want the user to delete the document.  How can I inform the user that the document wasn't deleted for a reason I determined through code?
    Tuesday, September 28, 2010 11:45 AM

Answers

  • Hi parri2bd,

                   

                    Thanks to share your problem.

                    For you issue, I know you want to pop a  dialog by javascript but not event handler’s error page. Using event handler is ,of course, a very good train of thought, but there are a little limits on it, I don’t think it’s 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.html

     

    3.       Customize your webpart  with usercontrol, add SPGridView control 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.

     

    Best Regards,

    Porter Wang

    • Marked as answer by KeFang Chen Thursday, October 7, 2010 9:48 AM
    Thursday, September 30, 2010 7:36 AM

All replies

  • You will have to use Event Reciever for it. Create event reciver and attach to your document library. When user try to delete the Item then corresponding event will fire, here you add your javascript logic to show popup dialog.

    Please go through this articles about the event recievers  Develop and deploy a SharePoint Event Receiver from the scratch

    To add javascript popup Pop-up message in event handler


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    • Edited by Sandip Patil Tuesday, September 28, 2010 12:04 PM new link added
    • Proposed as answer by Hemendra Agrawal Wednesday, September 29, 2010 4:34 AM
    • Unproposed as answer by parri2bd Wednesday, September 29, 2010 2:09 PM
    Tuesday, September 28, 2010 12:00 PM
  • Hi parri2bd,

                   

                    Thanks to share your problem.

                    For you issue, I know you want to pop a  dialog by javascript but not event handler’s error page. Using event handler is ,of course, a very good train of thought, but there are a little limits on it, I don’t think it’s 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.html

     

    3.       Customize your webpart  with usercontrol, add SPGridView control 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.

     

    Best Regards,

    Porter Wang

    • Marked as answer by KeFang Chen Thursday, October 7, 2010 9:48 AM
    Thursday, September 30, 2010 7:36 AM