private string GetSearchStringValidationInfoAsJson(BocAutoCompleteReferenceValueRenderingContext renderingContext)
        {
            string searchString            = StringUtility.EmptyToNull(renderingContext.Control.ValidSearchStringRegex) ?? "\\S*";
            string searchStringForDropDown = StringUtility.EmptyToNull(renderingContext.Control.ValidSearchStringForDropDownRegex) ?? searchString;
            string searchStringForDropDownDoesNotMatchRegexMessage =
                StringUtility.EmptyToNull(renderingContext.Control.SearchStringForDropDownDoesNotMatchRegexMessage)
                ?? GetResourceManager(renderingContext).GetString(ResourceIdentifier.SearchStringForDropDownDoesNotMatchRegexMessage);

            var jsonBuilder = new StringBuilder(1000);

            jsonBuilder.Append("{ ");
            jsonBuilder.Append("ValidSearchStringRegex : ");
            AppendStringValueOrNullToScript(jsonBuilder, searchString);
            jsonBuilder.Append(", ");
            jsonBuilder.Append("ValidSearchStringForDropDownRegex : ");
            AppendStringValueOrNullToScript(jsonBuilder, searchStringForDropDown);
            jsonBuilder.Append(", ");
            jsonBuilder.Append("SearchStringForDropDownDoesNotMatchRegexMessage : ");
            AppendStringValueOrNullToScript(jsonBuilder, searchStringForDropDownDoesNotMatchRegexMessage);
            jsonBuilder.Append(", ");
            jsonBuilder.Append("IgnoreSearchStringForDropDownUponValidInput : ");
            AppendBooleanValueToScript(jsonBuilder, renderingContext.Control.IgnoreSearchStringForDropDownUponValidInput);
            jsonBuilder.Append(" }");

            return(jsonBuilder.ToString());
        }
        private void RegisterInitializationScript(BocAutoCompleteReferenceValueRenderingContext renderingContext)
        {
            if (renderingContext.Control.IsReadOnly)
            {
                return;
            }

            if (!renderingContext.Control.Enabled)
            {
                return;
            }

            string key = renderingContext.Control.ClientID + "_InitializationScript";

            var script = new StringBuilder(1000);

            script.Append("$(document).ready( function() { BocAutoCompleteReferenceValue.Initialize(");
            script.AppendFormat("$('#{0}'), ", renderingContext.Control.GetTextValueName());
            script.AppendFormat("$('#{0}'), ", renderingContext.Control.GetKeyValueName());
            script.AppendFormat("$('#{0}'),", GetDropDownButtonName(renderingContext));

            if (renderingContext.Control.IsIconEnabled())
            {
                script.AppendFormat("$('#{0} .{1}'), ", renderingContext.Control.ClientID, CssClassCommand);
            }
            else
            {
                script.Append("null, ");
            }

            script.AppendFormat("'{0}', ", renderingContext.Control.ResolveClientUrl(renderingContext.Control.SearchServicePath));

            script.AppendFormat("{0}, ", renderingContext.Control.CompletionSetCount);
            script.AppendFormat("{0}, ", renderingContext.Control.DropDownDisplayDelay);
            script.AppendFormat("{0}, ", renderingContext.Control.DropDownRefreshDelay);
            script.AppendFormat("{0}, ", renderingContext.Control.SelectionUpdateDelay);

            script.Append(GetSearchStringValidationInfoAsJson(renderingContext));
            script.Append(", ");

            script.AppendFormat("'{0}', ", renderingContext.Control.NullValueString);
            AppendBooleanValueToScript(script, renderingContext.Control.TextBoxStyle.AutoPostBack ?? false);
            script.Append(", ");
            script.Append(GetSearchContextAsJson(renderingContext.SearchAvailableObjectWebServiceContext));
            script.Append(", ");
            AppendStringValueOrNullToScript(script, GetIconServicePath(renderingContext));
            script.Append(", ");
            script.Append(GetIconContextAsJson(renderingContext.IconWebServiceContext) ?? "null");
            script.Append(", ");
            script.Append(GetCommandInfoAsJson(renderingContext) ?? "null");
            script.Append(", ");
            script.Append(GetResourcesAsJson(renderingContext));
            script.Append("); } );");

            renderingContext.Control.Page.ClientScript.RegisterStartupScriptBlock(
                renderingContext.Control, typeof(IBocAutoCompleteReferenceValue), key, script.ToString());
        }
        public void Render(BocAutoCompleteReferenceValueRenderingContext renderingContext)
        {
            ArgumentUtility.CheckNotNull("renderingContext", renderingContext);

            base.Render(renderingContext);

            RegisterInitializationScript(renderingContext);

            CheckScriptManager(
                renderingContext.Control,
                "{0} '{1}' requires that the page contains a ScriptManager.",
                renderingContext.Control.GetType().Name,
                renderingContext.Control.ID);
        }
        private string GetResourcesAsJson(BocAutoCompleteReferenceValueRenderingContext renderingContext)
        {
            var resourceManager = GetResourceManager(renderingContext);
            var jsonBuilder     = new StringBuilder(1000);

            jsonBuilder.Append("{ ");
            jsonBuilder.Append("LoadIconFailedErrorMessage : ");
            AppendStringValueOrNullToScript(jsonBuilder, resourceManager.GetString(ResourceIdentifier.LoadIconFailedErrorMessage));
            jsonBuilder.Append(", ");
            jsonBuilder.Append("LoadDataFailedErrorMessage : ");
            AppendStringValueOrNullToScript(jsonBuilder, resourceManager.GetString(ResourceIdentifier.LoadDataFailedErrorMessage));
            jsonBuilder.Append(", ");
            jsonBuilder.Append("NoDataFoundMessage : ");
            AppendStringValueOrNullToScript(jsonBuilder, resourceManager.GetString(ResourceIdentifier.NoDataFoundMessage));
            jsonBuilder.Append(" }");

            return(jsonBuilder.ToString());
        }
 protected virtual IResourceManager GetResourceManager(BocAutoCompleteReferenceValueRenderingContext renderingContext)
 {
     return(GetResourceManager(typeof(ResourceIdentifier), renderingContext.Control.GetResourceManager()));
 }