title: Sitecore Cancel Publish Based On Conditions
body: <p>I have a requirement like when user clicks on the Publish Item button, I wanted to execute some custom code where I will run some validations against the current item and if it's all good, then the item will be published otherwise an alert will be displayed and the publish pipeline should be disabled.</p>
  <p>So for this I have created custom processor under publishItem pipeline and it all works good but when I am showing the alert it's giving me null reference exception.</p>
  <pre><code>Sitecore.Context.ClientPage.ClientResponse.Alert(message);
  </code></pre>
  <p>I am not sure what wrong I am doing here and is there any other way to achieve this ...Please suggest
  Below is the sample code which I wrote
  The below class is inherited from <strong>PublishItemProcessor</strong>.</p>
  <pre><code>public override void Process(PublishItemContext context)
          {
              Assert.ArgumentNotNull(context, &quot;context&quot;);
  
              // code goes here
  
              if (condition)
              {
                  string message = &quot;Required fields are missing&quot;;
                  context.AbortPipeline();                
                  Sitecore.Context.ClientPage.ClientResponse.Alert(message);
              }
          }
  
  &lt;publishItem&gt;
        &lt;processor type=&quot;Namespace.CheckRequiredChildItems, Namespace&quot; /&gt;
  &lt;/publishItem&gt;
  </code></pre>