Common MapTips
Common_MapTips_CSharp\StickyMapTips.aspx.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.
// 

public partial class StickyMapTips : System.Web.UI.Page 
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // Register script to pass the MapTips' graphics layer client ID to the client-side 
        // setupStickyMapTips function and to wire onMapZoom to the zoomStart event.  This
        // script will execute when the AJAX load event is fired.
        string setupStickyMapTipsScript = string.Format(@"
            function stickyMapTipsInit() {{
                // Put the logic in a timeout to ensure that the Web ADF JavaScript MapTips 
                // control is initialized first
                window.setTimeout(""setupStickyMapTips('{0}');"" +        
                    ""var map = $find('{1}');"" +
                    ""map.add_zoomStart(onMapZoom);"", 0);        
            }}
            Sys.Application.add_load(stickyMapTipsInit);",
            MapTips1.GraphicsLayerClientID, Map1.ClientID);
        System.Web.UI.ScriptManager.RegisterStartupScript(Page, Page.GetType(),
            "setupStickyMapTips", setupStickyMapTipsScript, true);

        Map1.ExtentChanged += 
            new ESRI.ArcGIS.ADF.Web.UI.WebControls.MapExtentChangeEventHandler(Map1_ExtentChanged);
    }



    void Map1_ExtentChanged(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs args)
    {
        // Create JavaScript needed to re-wire the MapTip anchoring logic to the MapTips' graphics
        // layer and bring any open MapTips to the front.  This is necessary because the MapTips
        // graphics layer is re-created when the extent is changed to update the features currently
        // shown.  Note that we have to put this logic in a timeout for it to execute after graphics
        // layer recreation.
        string addHandlerScript = string.Format(@"
            window.setTimeout(""$find('{0}').add_mouseOver(anchorMapTip);"" +
            ""bringMapTipsToFront()"", 0);", MapTips1.GraphicsLayerClientID);

        // Package the JavaScript in a callback result and add it to the Map's collection
        ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult addHandlerCallbackResult =
            ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(addHandlerScript);
        Map1.CallbackResults.Add(addHandlerCallbackResult);
    }
}