예제 #1
0
        protected override void OnInit(EventArgs e)
        {
            _clientScriptManagerWrapper = ClientScriptManagerWrapper.Initialize(Page.ClientScript);

            // TraceContext requires unique identifiers.
            // "Multiple controls with the same ID 'aspnetForm' were found.
            //  Trace requires that controls have unique IDs."
            // Source: TraceContext.AddNewControl(String, String, String, Int32, Int32)
            Int32 index;
            Int32.TryParse(PerRequestCache.Get("CustomHtmlForm.Index") as String, out index);
            ID = "aspnetForm_" + index;
            PerRequestCache.Set("CustomHtmlForm.Index", (++index).ToInvariantString());

            if (!NewPostBackScriptAdded && Page.Header != null) {
                var alreadyAddedNewScript = Page.Header.Controls.OfType<NewPostBackScript>().Any();
                if (!alreadyAddedNewScript) {
                    Page.Header.Controls.Add(new NewPostBackScript());
                    NewPostBackScriptAdded = true;
                }
            }

            base.OnInit(e);
        }
            internal static ClientScriptManagerWrapper Initialize(ClientScriptManager mgr)
            {
                var instance = PerRequestCache.Get("CustomHtmlForm.ClientScriptManagerWrapper") as ClientScriptManagerWrapper;
                if (instance != null)
                    return instance;

                instance = new ClientScriptManagerWrapper(mgr);
                PerRequestCache.Set("CustomHtmlForm.ClientScriptManagerWrapper", instance);
                return instance;
            }