A while back I needed to disable fields on a web page during submit and I found a utility written by Nancy Michell for MSDN Magazine. The utility covered the basic cases, but I found that I needed to use it for AJAX style calls as well as standard submits. So I modified the code to include an enable function as well. Finally I added exception handling around the disable and enable code to avoid pesky Javascript errors. The only thing I might change is to capture an array of the controls that were successfully disabled and then process only those controls on enable.

To use the disable utility, do the following:

// Method 1: Using the param string[] for controls
DisableHelper.DisableCtrlOnSubmit(this,
    "ServerForm.btnCancel",
    "ServerForm.btnSave");

// Method 2: Using the ArrayList of controls
aryDisableControls = new ArrayList();
aryDisableControls.Add("ConfigLoopForm.btnCancel");
aryDisableControls.Add("ConfigLoopForm.btnSave");
DisableHelper.DisableCtrlOnSubmit(this, aryDisableControls);

Here is the utility source:

using System;
using System.Collections;
using System.Text;

namespace Utility.Web.UI
{
    public class DisableHelper
    {
        /// <summary>
        /// Adds client-side javascript code to disable controls on a submit.
        /// </summary>
        /// <param name="Page">Reference to the current page</param>
        /// <param name="strControls">String array of client-side control names.</param>
        public static void DisableCtrlOnSubmit(
            System.Web.UI.Page Page, 
            params string[] strControls)
        {
            StringBuilder sbJS = new StringBuilder(200);
            sbJS.Append(@"
<script language=""javascript"">
function MSDisable() {
    try {
        if (Page_IsValid==false) return;
        window.setTimeout('MSDisableCtrls(true)',0);
    } catch (e) {
        window.setTimeout('MSDisableCtrls(true)',0);
    }
}

function MSEnable() {
    try {
        window.setTimeout('MSDisableCtrls(false)',0);
    } catch (e) {
        window.setTimeout('MSDisableCtrls(false)',0);
    }
}
"
                );

            sbJS.Append(@"
function MSDisableCtrls(value) {
"
                );

            foreach (string strControl in strControls)
            {
                sbJS.Append("\ttry { ");
                sbJS.Append(strControl);
                sbJS.Append(".disabled = value;");
                sbJS.Append(" } catch (e) {}\n");
            }

            sbJS.Append(@"
}
</script>
"
                );

            if (!Page.IsClientScriptBlockRegistered("MSDisableImpl"))
            {
                Page.RegisterClientScriptBlock(
                    "MSDisableImpl", 
                    sbJS.ToString());
            }

            Page.RegisterOnSubmitStatement("MSDisable", "MSDisable(false);");
        }

        /// <summary>
        /// Adds client-side javascript code to disable controls on a submit.
        /// </summary>
        /// <param name="Page">Reference to the current page</param>
        /// <param name="aryClientControlNames">ArrayList with the client-side control names</param>
        public static void DisableCtrlOnSubmit(
            System.Web.UI.Page Page, 
            ArrayList aryClientControlNames)
        {
            if (aryClientControlNames != null)
            {
                string[] strControls = (string[]) aryClientControlNames.ToArray(typeof(string));
                DisableCtrlOnSubmit(Page, strControls);
            }
        }

        private static void DiableCtrlOnSubmit(
            System.Web.UI.Page Page, 
            ArrayList aryClientControlNames)
        {
            DisableCtrlOnSubmit(Page, aryClientControlNames);
        }
    }
}