/// <devdoc>
        /// <para>Registers array declarations using the default array, <see langword='Page_Validators'/> .</para>
        /// </devdoc>
        protected virtual void RegisterValidatorDeclaration()
        {
            const string arrayName = "Page_Validators";
            string       element   = "document.getElementById(\"" + ClientID + "\")";

            // Cannot use the overloads of Register* that take a Control, since these methods only work with AJAX 3.5,
            // and we need to support Validators in AJAX 1.0 (Windows OS Bugs 2015831).
            if (!Page.IsPartialRenderingSupported)
            {
                Page.ClientScript.RegisterArrayDeclaration(arrayName, element);
            }
            else
            {
                ValidatorCompatibilityHelper.RegisterArrayDeclaration(this, arrayName, element);

                // Register a dispose script to make sure we clean up the page if we get destroyed
                // during an async postback.
                // We should technically use the ScriptManager.RegisterDispose() method here, but the original implementation
                // of Validators in AJAX 1.0 manually attached a dispose expando.  We added this code back in the product
                // late in the Orcas cycle, and we didn't want to take the risk of using RegisterDispose() instead.
                // (Windows OS Bugs 2015831)
                ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(BaseValidator), ClientID + "_DisposeScript",
                                                                   String.Format(
                                                                       CultureInfo.InvariantCulture,
                                                                       @"
document.getElementById('{0}').dispose = function() {{
    Array.remove({1}, document.getElementById('{0}'));
}}
",
                                                                       ClientID, arrayName), true);
            }
        }
 protected internal override void OnPreRender(EventArgs e)
 {
     base.OnPreRender(e);
     if (this.Enabled)
     {
         Page page = this.Page;
         if ((page != null) && (page.RequestInternal != null))
         {
             this.renderUplevel = (this.EnableClientScript && (page.Request.Browser.W3CDomVersion.Major >= 1)) && (page.Request.Browser.EcmaScriptVersion.CompareTo(new Version(1, 2)) >= 0);
         }
         if (this.renderUplevel)
         {
             string arrayValue = "document.getElementById(\"" + this.ClientID + "\")";
             if (!this.Page.IsPartialRenderingSupported)
             {
                 this.Page.ClientScript.RegisterArrayDeclaration("Page_ValidationSummaries", arrayValue);
             }
             else
             {
                 ValidatorCompatibilityHelper.RegisterArrayDeclaration(this, "Page_ValidationSummaries", arrayValue);
                 ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(ValidationSummary), this.ClientID + "_DisposeScript", string.Format(CultureInfo.InvariantCulture, "\r\ndocument.getElementById('{0}').dispose = function() {{\r\n    Array.remove({1}, document.getElementById('{0}'));\r\n}}\r\n", new object[] { this.ClientID, "Page_ValidationSummaries" }), true);
             }
         }
     }
 }
        /// <devdoc>
        ///    <para>
        ///       Registers code on the page for client-side validation.
        ///    </para>
        /// </devdoc>
        protected void RegisterValidatorCommonScript()
        {
            const string onSubmitScriptKey = "ValidatorOnSubmit";
            const string onSubmitScript    = "if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false;";

            // Cannot use the overloads of Register* that take a Control, since these methods only work with AJAX 3.5,
            // and we need to support Validators in AJAX 1.0 (Windows OS Bugs 2015831).
            if (!Page.IsPartialRenderingSupported)
            {
                if (Page.ClientScript.IsClientScriptBlockRegistered(typeof(BaseValidator), ValidatorIncludeScriptKey))
                {
                    return;
                }

                Page.ClientScript.RegisterClientScriptResource(typeof(BaseValidator), ValidatorFileName);
                Page.ClientScript.RegisterOnSubmitStatement(typeof(BaseValidator), onSubmitScriptKey, onSubmitScript);
                if (!IsUnobtrusive)
                {
                    Page.ClientScript.RegisterStartupScript(typeof(BaseValidator), ValidatorIncludeScriptKey, ValidatorStartupScript, addScriptTags: true);
                }
            }
            else
            {
                // Register the original validation scripts but through the new ScriptManager APIs
                ValidatorCompatibilityHelper.RegisterClientScriptResource(this, typeof(BaseValidator), ValidatorFileName);
                ValidatorCompatibilityHelper.RegisterOnSubmitStatement(this, typeof(BaseValidator), onSubmitScriptKey, onSubmitScript);
                if (!IsUnobtrusive)
                {
                    ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(BaseValidator), ValidatorIncludeScriptKey, ValidatorStartupScript, addScriptTags: true);
                }
            }
        }
        internal static void AddExpandoAttribute(Control control, HtmlTextWriter writer, string controlId, string attributeName, string attributeValue, bool encode)
        {
            Debug.Assert(control != null);
            Page page = control.Page;

            Debug.Assert(page != null);

            // if writer is not null, assuming the expando attribute is written out explicitly
            if (writer != null)
            {
                if (page.UnobtrusiveValidationMode != UnobtrusiveValidationMode.None)
                {
                    attributeName = UnobtrusivePrefix + attributeName;
                }
                writer.AddAttribute(attributeName, attributeValue, encode);
            }
            else
            {
                Debug.Assert(page.UnobtrusiveValidationMode == UnobtrusiveValidationMode.None, "The writer must have been passed in the Unobtrusive mode");

                // Cannot use the overload of RegisterExpandoAttribute that takes a Control, since that method only works with AJAX 3.5,
                // and we need to support Validators in AJAX 1.0 (Windows OS Bugs 2015831).
                if (!page.IsPartialRenderingSupported)
                {
                    // Fall back to ASP.NET 2.0 behavior
                    page.ClientScript.RegisterExpandoAttribute(controlId, attributeName, attributeValue, encode);
                }
                else
                {
                    // Atlas Partial Rendering support
                    // ScriptManager exists, so call its instance' method for script registration
                    ValidatorCompatibilityHelper.RegisterExpandoAttribute(control, controlId, attributeName, attributeValue, encode);
                }
            }
        }
        /// <internalonly/>
        /// <devdoc>
        ///    PreRender method.
        /// </devdoc>
        protected internal override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Act like invisible if disabled
            if (!Enabled)
            {
                return;
            }

            // work out uplevelness now
            Page page = Page;

            if (page != null && page.RequestInternal != null)
            {
                renderUplevel = (EnableClientScript && ShowValidationErrors &&
                                 page.Request.Browser.W3CDomVersion.Major >= 1 &&
                                 page.Request.Browser.EcmaScriptVersion.CompareTo(new Version(1, 2)) >= 0);
            }
            if (renderUplevel && !IsUnobtrusive)
            {
                const string arrayName = "Page_ValidationSummaries";
                string       element   = "document.getElementById(\"" + ClientID + "\")";

                // Cannot use the overloads of Register* that take a Control, since these methods only work with AJAX 3.5,
                // and we need to support Validators in AJAX 1.0 (Windows OS Bugs 2015831).
                if (!Page.IsPartialRenderingSupported)
                {
                    Page.ClientScript.RegisterArrayDeclaration(arrayName, element);
                }
                else
                {
                    ValidatorCompatibilityHelper.RegisterArrayDeclaration(this, arrayName, element);

                    // Register a dispose script to make sure we clean up the page if we get destroyed
                    // during an async postback.
                    // We should technically use the ScriptManager.RegisterDispose() method here, but the original implementation
                    // of Validators in AJAX 1.0 manually attached a dispose expando.  We added this code back in the product
                    // late in the Orcas cycle, and we didn't want to take the risk of using RegisterDispose() instead.
                    // (Windows OS Bugs 2015831)
                    ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(ValidationSummary), ClientID + "_DisposeScript",
                                                                       String.Format(
                                                                           CultureInfo.InvariantCulture,
                                                                           @"
(function(id) {{
    var e = document.getElementById(id);
    if (e) {{
        e.dispose = function() {{
            Array.remove({1}, document.getElementById(id));
        }}
        e = null;
    }}
}})('{0}');
",
                                                                           ClientID, arrayName), true);
                }
            }
        }
        protected virtual void RegisterValidatorDeclaration()
        {
            string arrayValue = "document.getElementById(\"" + this.ClientID + "\")";

            if (!this.Page.IsPartialRenderingSupported)
            {
                this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", arrayValue);
            }
            else
            {
                ValidatorCompatibilityHelper.RegisterArrayDeclaration(this, "Page_Validators", arrayValue);
                ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(BaseValidator), this.ClientID + "_DisposeScript", string.Format(CultureInfo.InvariantCulture, "\r\ndocument.getElementById('{0}').dispose = function() {{\r\n    Array.remove({1}, document.getElementById('{0}'));\r\n}}\r\n", new object[] { this.ClientID, "Page_Validators" }), true);
            }
        }
 protected void RegisterValidatorCommonScript()
 {
     if (!this.Page.IsPartialRenderingSupported)
     {
         if (!this.Page.ClientScript.IsClientScriptBlockRegistered(typeof(BaseValidator), "ValidatorIncludeScript"))
         {
             this.Page.ClientScript.RegisterClientScriptResource(typeof(BaseValidator), "WebUIValidation.js");
             this.Page.ClientScript.RegisterStartupScript(typeof(BaseValidator), "ValidatorIncludeScript", "\r\nvar Page_ValidationActive = false;\r\nif (typeof(ValidatorOnLoad) == \"function\") {\r\n    ValidatorOnLoad();\r\n}\r\n\r\nfunction ValidatorOnSubmit() {\r\n    if (Page_ValidationActive) {\r\n        return ValidatorCommonOnSubmit();\r\n    }\r\n    else {\r\n        return true;\r\n    }\r\n}\r\n        ", true);
             this.Page.ClientScript.RegisterOnSubmitStatement(typeof(BaseValidator), "ValidatorOnSubmit", "if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false;");
         }
     }
     else
     {
         ValidatorCompatibilityHelper.RegisterClientScriptResource(this, typeof(BaseValidator), "WebUIValidation.js");
         ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(BaseValidator), "ValidatorIncludeScript", "\r\nvar Page_ValidationActive = false;\r\nif (typeof(ValidatorOnLoad) == \"function\") {\r\n    ValidatorOnLoad();\r\n}\r\n\r\nfunction ValidatorOnSubmit() {\r\n    if (Page_ValidationActive) {\r\n        return ValidatorCommonOnSubmit();\r\n    }\r\n    else {\r\n        return true;\r\n    }\r\n}\r\n        ", true);
         ValidatorCompatibilityHelper.RegisterOnSubmitStatement(this, typeof(BaseValidator), "ValidatorOnSubmit", "if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false;");
     }
 }
 internal static void AddExpandoAttribute(Control control, HtmlTextWriter writer, string controlId, string attributeName, string attributeValue, bool encode)
 {
     if (writer != null)
     {
         writer.AddAttribute(attributeName, attributeValue, encode);
     }
     else
     {
         Page page = control.Page;
         if (!page.IsPartialRenderingSupported)
         {
             page.ClientScript.RegisterExpandoAttribute(controlId, attributeName, attributeValue, encode);
         }
         else
         {
             ValidatorCompatibilityHelper.RegisterExpandoAttribute(control, controlId, attributeName, attributeValue, encode);
         }
     }
 }
 internal void RegisterUnobtrusiveScript()
 {
     ClientScriptManager.EnsureJqueryRegistered();
     ValidatorCompatibilityHelper.RegisterClientScriptResource(this, jqueryScriptKey);
 }