Exemplo n.º 1
0
        protected void RegisterHtml(StringBuilder sb, Page pageHolder)
        {
            string html = BaseScriptBuilder.RenderControl(this.Control, pageHolder);

            if (!string.IsNullOrEmpty(html))
            {
                sb.Insert(0, html);
            }
        }
        public virtual string Build(LazyMode mode)
        {
            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                if (cmp != null)
                {
                    cmp.PreventRenderTo = true;
                }

                this.Control.IsDynamicLazy     = true;
                this.Control.TopDynamicControl = true;

                StringBuilder sb = new StringBuilder();

                List <BaseControl> childControls = this.FindControls(this.Control, false, null, null, null);
                childControls.Insert(0, this.Control);

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.DeferInitScriptGeneration = true;

                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                var html = this.Control is INoneContentable ? null : BaseScriptBuilder.RenderControl(this.Control, null);

                foreach (BaseControl c in childControls)
                {
                    c.DeferInitScriptGeneration = false;
                }

                List <BaseControl> newChildControls = this.FindControls(this.Control, false, sb, null, null);
                newChildControls.Insert(0, this.Control);

                foreach (BaseControl c in newChildControls)
                {
                    if (!childControls.Contains(c) && (c.Visible || Object.ReferenceEquals(c, this.Control)))
                    {
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                childControls = newChildControls;

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.OnClientInit(true);
                        c.RegisterBeforeAfterScript();
                    }
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control))
                        {
                            string initScript;

                            if (this.Control is ICustomConfigSerialization)
                            {
                                initScript = ((ICustomConfigSerialization)c).ToScript(c);
                            }
                            else
                            {
                                initScript = mode == LazyMode.Instance ? "new {0}({1})".FormatWith(c.InstanceOf, c.InitialConfig) : c.InitialConfig;
                            }

                            this.ScriptClientInitBag.Add(c.ClientInitID, initScript);
                        }
                        else
                        {
                            string script = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary <string, string> {
                                { "ref", c.IsLazy ? c.ClientInitID : "init_script" },
                                { "index", ResourceManager.ScriptOrderNumber.ToString() }
                            }, c.BuildInitScript());

                            this.ScriptClientInitBag.Add(c.ClientInitID, script);
                        }

                        c.AlreadyRendered = true;
                    }
                }

                if (this.ScriptClientInitBag.Count > 0)
                {
                    foreach (KeyValuePair <string, string> item in this.ScriptClientInitBag)
                    {
                        sb.Append(this.ScriptClientInitBag[item.Key]);
                    }
                }

                var initToken = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                    { "id", "init_script" }
                });

                if (html.IsNotEmpty())
                {
                    sb.Insert(sb.ToString().IndexOf('{') + 1, "contentHtml:function(){{{0}{1}}},".FormatWith(html, initToken));
                }
                else
                {
                    sb.Append(initToken);
                }

                this.script = sb.ToString();
            }

            var config = Transformer.NET.Html.HtmlTransformer.Transform(this.script);

            return(config);
        }