Common Custom JavaScript
Common_CustomJavaScript_CSharp\App_Code\CustomTool.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.
// 

namespace CustomTools
{
    // Shows how to retrieve arguments from callbacks and postbacks
    public class CustomArgumentsTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction
    {
        #region IMapServerToolAction Members

        void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction(
            ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs)
        {
            System.Collections.Specialized.NameValueCollection nameValueCollectionInsideArg = null;

            // Check whether the page request was issued using a callback or a postback.  A callback is used if no
            // ScriptManager is on the page containing the tool.  Otherwise, a partial postback is used.
            if (toolEventArgs.Control.Page.IsCallback)
            {
                // Get the callback arguments from the __CALLBACKPARAM argument of the page request parameters
                string callbackArguments = toolEventArgs.Control.Page.Request.Params["__CALLBACKPARAM"];
                nameValueCollectionInsideArg = 
                    ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection(callbackArguments);

                // Get the value of the DropDownList1 server control, which has been manually added to the tool's
                // arguments via JavaScript in AddArgumentsToTool.aspx
                string dropDownListValue = nameValueCollectionInsideArg["DropDownList1"];
                
                // Get the value of the custom argument created via JavaScript in AddArgumentsToTool.aspx
                string inlineValue = nameValueCollectionInsideArg["inlineArgument"];
            }
            else
            {
                // Get the value of the DropDownList1 server control, which is automatically included in postbacks
                // (partial postbacks included) due to its being a server control
                string dropDownListValue = toolEventArgs.Control.Page.Request.Params["DropDownList1"];

                // Get the postback event arguments from the __EVENTARGUMENT argument of the page request parameters
                string postbackEventArguments = toolEventArgs.Control.Page.Request.Params["__EVENTARGUMENT"];
                nameValueCollectionInsideArg = 
                    ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection(
                    postbackEventArguments);

                // Get the value of the custom argument created via JavaScript in AddArgumentsToTool.aspx
                string inlineValue = nameValueCollectionInsideArg["inlineArgument"];
            }
        }

        #endregion
    }
}