Recently a customer came up with an issue and wanted to create a custom submit action button handler in CMS 2002 and send email to the editor/moderator. The requirement was that the user should be able to select which editor or moderator the email needs to be sent. The customer was following the article available at http://msdn2.microsoft.com/en-us/library/ms964282.aspx

 

But the code given in the article does not do Posting.Submit() nor does it handles the PostBack events in JavaScript. It just uses the redirect which do not solve our purpose. Researched a little and dig deeper into the MCMS belly and created the following code to achieve customer’s requirements.

 

Just compile this code into a Control and replace the CMSConsole:SubmitAction (Microsoft.ContentManagement.WebControls.ConsoleControls.SubmitAction) from the ConsoleContext.ascx with the below given SubmitAction control and you are all set to go !

   1: using System;
   2: using System.Data;
   3: using System.Configuration;
   4: using System.Web.UI;
   5: using System.Web.UI.WebControls;
   6: using System.Web.Mail;
   7: using Microsoft.ContentManagement.Publishing;
   8: using Microsoft.ContentManagement.WebControls;
   9: using Microsoft.ContentManagement.WebControls.ConsoleControls;
  10:  
  11: namespace MySubmitEmail
  12: {
  13:     /// <summary>
  14:     /// Summary description for MSSubmitEmail
  15:     /// </summary>
  16:     public class MSSubmitEmail : SubmitAction
  17:     {
  18:         protected override void PerformActionBehavior()
  19:         {
  20:  
  21:             string sEmail = this.Page.Request.QueryString.Get("email").ToString();
  22:  
  23:             if(CmsHttpContext.Current.Mode != PublishingMode.Update)
  24:             {
  25:                 if(this.Page.Request.QueryString.Get("email") == null)
  26:                 {
  27:                     this.Page.Response.Redirect(CmsHttpContext.Current.Posting.UrlModeUpdate + "&email=someid@email.local",true);
  28:                 }
  29:                 else
  30:                 {
  31:                     this.Page.Response.Redirect(CmsHttpContext.Current.Posting.UrlModeUpdate,true);
  32:                 }
  33:             }
  34:  
  35:             CmsHttpContext.Current.Posting.Submit();
  36:             CmsHttpContext.Current.CommitAll();
  37:             base.PerformActionBehavior();
  38:             
  39:             this.Page.Response.Redirect(CmsHttpContext.Current.Posting.UrlModeUnpublished,true);
  40:         }
  41:  
  42:         public override string Text
  43:         {
  44:             get
  45:             {
  46:                 return "Submit with email";
  47:             }
  48:             set
  49:             {
  50:                 base.Text = value;
  51:             }
  52:         }
  53:  
  54:         public override string ActionJavascript
  55:         {
  56:             get
  57:             {
  58:                 string sJavaScript;
  59:                 string sURL = "";
  60:  
  61:                 sJavaScript = "var sDLGResult;"
  62:                     + "sDLGResult = window.showModalDialog"
  63:                     + "('/select.html'," + "'','scroll:no;dialogHeight:250px;"
  64:                     + "dialogWidth:500px;edge:sunken;"
  65:                     + "center:Yes;help:No;resizable:No;"
  66:                     + "status:No;');"
  67:                     + "if (sDLGResult!='Cancelled')"
  68:                     + "{ alert(sDLGResult); ";
  69:  
  70:                 sURL = this.UrlPostback;
  71:  
  72:                 if(this.Page.Request.QueryString.Get("email") == null)
  73:                 {
  74:                     if(! (this.UrlPostback.ToString().IndexOf("&email=") > 0) )
  75:                         sURL += "&email=";
  76:  
  77:                     sJavaScript += "CMS_preparePostbackUrl('" + sURL + "' + sDLGResult);" + this.Page.GetPostBackEventReference(this, "");
  78:                 }
  79:                 else
  80:                 {
  81:                     sJavaScript += "CMS_preparePostbackUrl('" + sURL + "');" + this.Page.GetPostBackEventReference(this, "");
  82:                 }
  83:  
  84:                 //We dont need to do the navigate, we need a postback
  85:                 //sJavaScript += "window.navigate(window.location + '&chan=' + sDLGResult);"
  86:  
  87:                 sJavaScript += "}";
  88:                 return sJavaScript;
  89:             }
  90:         }
  91:     }
  92: }

 

Happy Coding…