0

I've added this Event Receiver (based on what I found here):

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace PostTravelWizard.PostTravelItemEventReceiver
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class PostTravelItemEventReceiver : SPItemEventReceiver
    {
       /// <summary>
       /// An item was added.
       /// </summary>
       public override void ItemAdded(SPItemEventProperties properties)
       {
           base.ItemAdded(properties);
           //GeneratePDF(); <= "The name 'GeneratePDF' does not exist in the current context
       }

       /// <summary>
       /// The list received a context event.
       /// </summary>
       public override void ContextEvent(SPItemEventProperties properties)
       {
           base.ContextEvent(properties);
           // TODO: What "context event" occurs here? To what event should I respond?
       }

    }
}

I'm hoping to, when a List is updated (from the client side/Javascript), then retrieve those values in the code-behind to generate a PDF file. I have this code in my *.ascx.cs file:

public partial class PostTravelWizardWebPartUserControl : UserControl
{
    . . .

    public void GeneratePDF(PostTravelData ptd)
    {
        ;//bla
    }

...but it's not letting my call GeneratePDF() from the Event Receiver - it fails with ""The name 'GeneratePDF' does not exist in the current context"

Why? and how can I rectify this asunto?

1

Because Event Receiver does not have access to context.

More precisely - it can have access to context, if You realize workaround that initializes context in constructor.. But it is wrong.

Because event receiver works on server. Imagine that You upload file to library, copying it by Webdav in Windows Explorer - what context will You get in this case?

So the right method is to change the logic, or if You need to bypass data between controls and event receiver - use a storage to Your data(by example Property Bag, List, configuration files or else)

  • By "have have" did you mean "not have"? I am going to store the data in a list (from jQuery, via an AJAX call), but I need to know on the server-side when the List has been updated, so I can act on it from there (to generate a PDF file using iTextSharp). – B. Clay Shannon Sep 19 '15 at 15:19
  • Fixed, one "have" was excess.. << from the client side/Javascript<< - I didn't analyze what are You doing, but I think in this case You can write value to cookie in javascript, and read value from cookie on server-side. Or review entire logic, cause You mixed Event receiver, javascript, and User Control. By example create webpart with button "Generate PDF". – Gennady G Sep 19 '15 at 17:34

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.