0
namespace SXPSetDisposalDate.SetDisposalDate
{
 public class SetDisposalDate : SPItemEventReceiver{

            /// <summary>
            /// An item is being checked in.
            /// </summary>
            public override void ItemCheckingIn(SPItemEventProperties properties)
            {

                 //if not migrated
                    if (ctName != rejectedcT)
                    {

                    }
                    else
                    {
                        //reject save because Content Type is migrated

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "Exception", "alert('Stop')", true);                
                     }
              }
  }
}

I have this code on an event receiver in SharePoint which triggers when an item is checked in. When the content type doesn't equal a certain name then an alert pops up telling them to not use the content type selected. I am getting an error that reads

the best overloaded method match for ScriptManager.RegisterStartupScript has some invalid arguments

what am I doing wrong?

1
  • How are you getting the Page object? Dec 23, 2016 at 14:15

1 Answer 1

0

Try it as below:

public override void ItemCheckingIn(SPItemEventProperties properties)
{

    try
    {
        //if not migrated
        if (ctName != rejectedcT)
        {

        }
        else
        {
            //reject save because Content Type is migrated
           properties.ErrorMessage = "Stop, add the correct content type";
           properties.Status = SPEventReceiverStatus.CancelWithError;
           properties.Cancel = true;
        }
    }
    catch(Exception ex)
    {
        properties.ErrorMessage = "Stop, add the correct content type";
        properties.Status = SPEventReceiverStatus.CancelWithError;
        properties.Cancel = true;
    }
}
5
  • still the same error
    – ben
    Dec 23, 2016 at 9:24
  • @ben - check updated code. Dec 23, 2016 at 9:32
  • there is nothing more user friendly?
    – ben
    Dec 23, 2016 at 9:53
  • You can create your own custom page/ application page and redirect user to it using properties.Cancelwithredirecturl instead. On that page, you can customize look and feel. Dec 23, 2016 at 10:19
  • properties.Cancel is deprecated, properties.Status should be enough : msdn.microsoft.com/en-us/library/… Dec 23, 2016 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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