CrossPostbacks with MCMS 2002 SP2

ASP.NET 2.0 introduces a new feature to allow cross-Postbacks to other webforms using the PostBackUrl property.

This method is very nice and allows to replace ugly workaround that were required in ASP.NET 1.x like using GET requests with query strings or adding client side script that cleared the viewstate form field.

There is only one caveat with this new method: It does not work with MCMS 2002. MCMS 2002 Service Pack 2 which is required to allow MCMS to work with ASP.NET 2.0 adds some additional client side javascript code that prevents the PostBackUrl property from working properly as it always changes the Url back to the MCMS template file. So the logic of this client side script does not handle the cross-Postback situation correct.

To overcome this limitation it is required to extend the client side javascript with some logic that allows the script to recognize the cross-Postback correct and not to change the Url back to the MCMS template file.

The good thing here is that the MCMS javascript code already contains the logic not to change the URL back if the __CMS_PostbackFormBeenReset variable contains a value of true. This is used in some MCMS internal console actions. So we only need to ensure that this variable is set to true when a cross postback happens. As all cross Postback calls use the WebForm_DoPostBackWithOptions javascript routine injected by ASP.NET 2.0 the easiest way to achieve this is to redirect the calls to this routine to our own routine, set the __CMS_PostbackFormBeenReset variable and then to call the original WebForm_DoPostBackWithOptions routine.

As this client side code would have to be added to all template files the best solution is to add the logic using a HttpModule that only has to be added to the web.config once and then ensures that the script will be added automatically to all template files:

using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.WebControls;

namespace StefanG.ASPNET20_HttpModule

    public class ASPNET20_CrossPostbackCorrection : IHttpModule 
        public void Init(HttpApplication httpApp) 
            httpApp.PreRequestHandlerExecute += 
                        new EventHandler(this.OnPreRequestHandlerExecute);

        public void Dispose() 
            // Nothing to do.

        public void OnPreRequestHandlerExecute(object sender, EventArgs e) 
            HttpContext ctx = ((HttpApplication)sender).Context;
            IHttpHandler handler = ctx.Handler;

            // only execute for ASP.NET handler
            // not for custom http handlers or for the ASP.NET 2.0 resource handlers.

            if (handler.GetType().ToString().StartsWith(“ASP.”))
                    if (CmsHttpContext.Current.ChannelItem != null)
                       ((System.Web.UI.Page)handler).Init += new EventHandler(this.OnInit);
                    // this will happen if the request is in the middle of an expired forms authentication 
                    // login
 we just ignore this.

        string Override_WebForm_DoPostBackWithOptions =
            ”   if ( typeof WebForm_DoPostBackWithOptions != \”undefined\” )\n” +
            ”   {\n” +
            ”       __CrossPostBack_Backup_WebForm_DoPostBackWithOptions = “ +
            ”                 WebForm_DoPostBackWithOptions;\n”
            ”       WebForm_DoPostBackWithOptions = “ + 
            ”                __CrossPostBack_Redirect_WebForm_DoPostBackWithOptions;\n”
            ”   }\n” +
            ”   function __CrossPostBack_Redirect_WebForm_DoPostBackWithOptions(options)” +
            ”   {\n” +
            ”       __CMS_PostbackFormBeenReset = true;\n” +
            ”       __CrossPostBack_Backup_WebForm_DoPostBackWithOptions(options);\n” +
            ”   }\n”;

        public void OnInit(object sender, EventArgs eventArgs)
p;      System.Web.UI.Page currentPage = sender as System.Web.UI.Page;
                Override_WebForm_DoPostBackWithOptions, true); 



  1. Currently we have a couple of known issues with MCMS 2002 SP2:

    DCA complains about missing priviledges…


  2. Could Callback calls not work in ASP.NET 2.0 with MCMS because of this?


  3. As some of you already noticed: GotDotNet is now down and the code samples previously hosted there have


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.