Common Context menu
Common_ContextMenu_CSharp\App_Code\Utility.cs
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public static class Utility
{
    public static ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection ProcessMapToolError(string message)
    {
        // Create a collection of callback results to 1) display an error message and 2) reset map cursor.
        string jsAlertException = "alert('" + message + "')";
        ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult alertCallbackResult =
            new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(null, null, "javascript", jsAlertException);

        string jsChangeCursor = "map.divObject.style.cursor = map.cursor";
        ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult cursorCallbackResult =
            new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(null, null, "javascript", jsChangeCursor);

        ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection callbackResultCollection =
            new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection();
        callbackResultCollection.Add(alertCallbackResult);
        callbackResultCollection.Add(cursorCallbackResult);

        return callbackResultCollection;
    }

    public static System.Web.UI.Control FindControl(string control, System.Web.UI.Page page)
    {
        System.Web.UI.Control buddyControl = page.FindControl(control);
        if (buddyControl == null)
        {
            string webPartControl = GetControlUniqueID(control, page.Controls);
            if (webPartControl != null)
                buddyControl = page.FindControl(webPartControl);
            else
                buddyControl = page.FindControl(control);
        }
        return buddyControl;
    }

    public static string GetControlUniqueID(string controlID, System.Web.UI.ControlCollection controls)
    {
        System.Web.UI.Control control;
        string uniqueID = null;
        for (int i = 0; i < controls.Count; ++i)
        {
            control = controls[i];
            if (control.ID == controlID)
            {
                uniqueID = control.UniqueID;
                break;
            }
            if (control.Controls.Count > 0)
            {
                uniqueID = GetControlUniqueID(controlID, control.Controls);
                if (uniqueID != null)
                    break;
            }
        }
        return uniqueID;
    }
}