1

Is it possible to call JavaScript file in any of the events in event receiver in SharePoint 2013.

2 Answers 2

2

You can not run JS code because the event receiver is not running in the HTTP Context.

You can run your javascript code from the newForm or a custom newform instead, maybe before the event (handled by the event receiver) fire.

0

JavaScript is executed in Web Browser. It interacts with objects in DOM as well as uses functionality supported by Browsers.

You should re-write what you have in JavaScript.

You can try below code - It is not tested

public class CustomReceiver : SPItemEventReceiver    
{  
   private HttpContext currentContext;        
   static HttpContext _stCurrentContext;        

   public CustomReceiver()        
   {            
       currentContext = HttpContext.Current;         
   }  

   public override void ItemAdding(SPItemEventProperties properties)        
   {                        
        base.ItemUpdating(properties);

        _stCurrentContext = currentContext;
        if (_stCurrentContext != null)
        { 
           _stCurrentContext.Response.Write("<script>alert('JavaScript Invoked');</script>");
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.