Наследование: System.Web.UI.Page, ISelfRenderingPage
Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual string SelfRender()
        {
            if (HttpContext.Current == null)
            {
                return("");
            }

            var pageHolder = new SelfRenderingPage();

            if (!(this is ResourceManager))
            {
                var newMgr = new ResourceManager();
                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles  = ResourceLocationType.None;
                newMgr.IDMode        = IDMode.Explicit;
                newMgr.IsSelfRender  = true;
                newMgr.IsDynamic     = true;
                pageHolder.Controls.Add(newMgr);
            }

            this.IsSelfRender = true;
            this.IDMode       = IDMode.Explicit;

            pageHolder.Controls.Add(this);

            StringWriter output = new StringWriter();

            HttpContext.Current.Server.Execute(pageHolder, output, true);
            this.IsSelfRender = false;

            return(output.ToString());
        }
Пример #2
0
        public static string RenderControl(Control control, Page pageHolder)
        {
            if (pageHolder == null)
            {
                pageHolder = new SelfRenderingPage();

                ResourceManager newMgr = new ResourceManager(true);
                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles  = ResourceLocationType.None;
                newMgr.IDMode        = IDMode.Explicit;
                newMgr.IsDynamic     = true;
                pageHolder.Controls.Add(newMgr);

                pageHolder.Controls.Add(control);
            }

            StringWriter output = new StringWriter();

            HttpContext.Current.Server.Execute(pageHolder, output, true);

            StringBuilder sb = new StringBuilder();
            //MatchCollection mc = Regex.Matches(output.ToString(), string.Concat(XControl.TOP_DYNAMIC_CONTROL_TAG_S, "(.*?)", XControl.TOP_DYNAMIC_CONTROL_TAG_E), RegexOptions.Singleline);
            MatchCollection mc = TopDynamic_RE.Matches(output.ToString());

            foreach (Match m in mc)
            {
                sb.Append(m.Groups[1].Value);
            }

            return(sb.ToString() ?? "");
        }
Пример #3
0
        public static string RenderControl(Control control, Page pageHolder)
        {
            if (pageHolder == null)
            {
                pageHolder = new SelfRenderingPage();
                pageHolder.Controls.Add(control);
            }

            StringWriter output = new StringWriter();

            HttpContext.Current.Server.Execute(pageHolder, output, true);

            StringBuilder sb = new StringBuilder();
            //MatchCollection mc = Regex.Matches(output.ToString(), string.Concat(XControl.TOP_DYNAMIC_CONTROL_TAG_S, "(.*?)", XControl.TOP_DYNAMIC_CONTROL_TAG_E), RegexOptions.Singleline);
            MatchCollection mc = TopDynamic_RE.Matches(output.ToString());

            foreach (Match m in mc)
            {
                sb.Append(m.Groups[1].Value);
            }

            return(sb.ToString() ?? "");
        }
Пример #4
0
        public virtual string Build(bool selfRendering, bool forceResources)
        {
            this.ForceResources = forceResources;
            if (this.script == null)
            {
                Page pageHolder = null;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering  = true;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager rm = new ResourceManager(true);
                    rm.RenderScripts = ResourceLocationType.None;
                    rm.RenderStyles  = ResourceLocationType.None;
                    rm.IDMode        = IDMode.Explicit;
                    rm.IsDynamic     = true;
                    pageHolder.Controls.Add(rm);
                    this.ResourceManager = rm;

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl <ResourceManager>(pageHolder);
                    this.ResourceManager = newMgr;
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                this.Control.ContentUpdated = this.Control.HasContent();
                AbstractContainer container = this.Control as AbstractContainer;
                if (container != null && container.Items.Count > 0)
                {
                    sb.AppendFormat("{0}.removeAll();", this.Control.ClientID);
                }

                List <BaseControl> childControls = this.FindControls(this.Control, selfRendering, sb, null, null);

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible)
                    {
                        c.DeferInitScriptGeneration = selfRendering;
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    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)
                    {
                        c.OnClientInit(true);
                        c.RegisterBeforeAfterScript();
                    }
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible)
                    {
                        string initScript = c.BuildInitScript();
                        if (!string.IsNullOrEmpty(initScript))
                        {
                            if (this.layoutItems.Contains(c))
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, this.Control.ClientID.ConcatWith(".add(", initScript, ");"));
                            }
                            else
                            {
                                initScript = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary <string, string> {
                                    { "ref", c.IsLazy ? c.ClientInitID : "init_script" },
                                    { "index", ResourceManager.ScriptOrderNumber.ToString() }
                                }, initScript);
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript);
                            }
                        }

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair <long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

                foreach (KeyValuePair <long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                //if (selfRendering)
                //{
                //    this.RegisterHtml(sb, pageHolder);
                //}

                if (container != null && container.Items.Count > 0)
                {
                    sb.AppendFormat("{0}.doLayout();", this.Control.ClientID);
                }

                sb.Append(Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                    { "id", "init_script" }
                }));
                this.script = this.RegisterResources(sb.ToString());
            }

            return(Transformer.NET.Html.HtmlTransformer.Transform(this.script));
        }
        public static string RenderControl(Control control, Page pageHolder)
        {
            if (pageHolder == null)
            {
                pageHolder = new SelfRenderingPage();
                
                ResourceManager newMgr = new ResourceManager(true);
                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles = ResourceLocationType.None;
                newMgr.IDMode = IDMode.Explicit;
                newMgr.IsDynamic = true;
                pageHolder.Controls.Add(newMgr);

                pageHolder.Controls.Add(control);
            }

            StringWriter output = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, output, true);

            StringBuilder sb = new StringBuilder();
            //MatchCollection mc = Regex.Matches(output.ToString(), string.Concat(XControl.TOP_DYNAMIC_CONTROL_TAG_S, "(.*?)", XControl.TOP_DYNAMIC_CONTROL_TAG_E), RegexOptions.Singleline);
            MatchCollection mc = TopDynamic_RE.Matches(output.ToString());

            foreach (Match m in mc)
            {
                sb.Append(m.Groups[1].Value);
            }

            return sb.ToString() ?? "";
        }
        public virtual string Build(RenderMode mode, string element, int? index, bool selfRendering, bool forceResources, string method, bool forceLazy)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                switch (mode)
                {
                    case RenderMode.RenderTo:
                        if (cmp == null)
                        {
                            throw new Exception("RenderTo mode can be applied to only a AbstractComponent.");
                        }

                        if (string.IsNullOrEmpty(element))
                        {
                            element = "={Ext.net.ResourceMgr.getRenderTarget()}";
                        }

                        if (this.Control.IsLazy)
                        {
                            throw new Exception("Lazy control can be rendered with Automatic render mode only.");
                        }

                        cmp.RenderTo = element;

                        break;
                    case RenderMode.AddTo:
                    case RenderMode.InsertTo:
                        if (cmp == null)
                        {
                            throw new Exception("AddTo mode can be applied to only a AbstractComponent.");
                        }

                        if (string.IsNullOrEmpty(element))
                        {
                            throw new Exception("You must specify an Element for the AddTo mode.");
                        }

                        if (this.Control.IsLazy)
                        {
                            //throw new Exception("Lazy controls can be rendered in Automatic mode only.");
                        }

                        if (mode == RenderMode.InsertTo && index == null)
                        {
                            throw new Exception("You have to provide the index for the InsertTo mode.");
                        }

                        cmp.PreventRenderTo = true;
                        break;
                }

                Page pageHolder = null;
                bool isLazy = this.Control.IsLazy;
                this.Control.IsDynamicLazy = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo);
                Control parent = null;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering = true;
                this.Control.ForceLazy = forceLazy;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager(true);
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles = ResourceLocationType.None;
                    newMgr.IDMode = IDMode.Explicit;
                    newMgr.IsDynamic = true;
                    pageHolder.Controls.Add(newMgr);
					this.ResourceManager = newMgr;

                    pageHolder.Controls.Add(this.Control);   
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl<ResourceManager>(pageHolder);
					this.ResourceManager = newMgr;
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                if (this.Control.ClientID.IsNotEmpty() && !this.Control.IsGeneratedID)
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

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

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

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

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    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();
                    }
                }

                string methodTemplate = string.Concat(".",method ?? "add","(");

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = string.Concat(".", method ?? "insert", "(", index.Value, ",");
                }
                
                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control) && isLazy)
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);
                            
                            string initScript = c.BuildInitScript();                            

                            if (selfRendering)
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript.ConcatWith(initScript.EndsWith(";") ? "" : ";", parent.ClientID.ConcatWith(methodTemplate, c.ClientID, ");")));
                            }
                            else
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, c.ParentComponent.ClientID.ConcatWith(methodTemplate, initScript, ");"));
                            }

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        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;

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    var elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Append(elementGet.ConcatWith(methodTemplate, this.Control.ForceLazy ? this.Control.ConfigID : this.Control.ClientID, ");"));
                }

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }
                
                this.script = this.RegisterResources(sb.ToString());                
            }

            this.Control.ForceLazy = false;

            return Transformer.NET.Html.HtmlTransformer.Transform(this.script);
        }
Пример #7
0
        public virtual string Build(RenderMode mode, string element, int?index, bool selfRendering, bool forceResources, string method, bool forceLazy)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                switch (mode)
                {
                case RenderMode.RenderTo:
                    if (cmp == null)
                    {
                        throw new Exception("RenderTo mode can be applied to only a AbstractComponent.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        element = "={Ext.net.ResourceMgr.getRenderTarget()}";
                    }

                    if (this.Control.IsLazy)
                    {
                        throw new Exception("Lazy control can be rendered with Automatic render mode only.");
                    }

                    cmp.RenderTo = element;

                    break;

                case RenderMode.AddTo:
                case RenderMode.InsertTo:
                    if (cmp == null)
                    {
                        throw new Exception("AddTo mode can be applied to only a AbstractComponent.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        throw new Exception("You must specify an Element for the AddTo mode.");
                    }

                    if (this.Control.IsLazy)
                    {
                        //throw new Exception("Lazy controls can be rendered in Automatic mode only.");
                    }

                    if (mode == RenderMode.InsertTo && index == null)
                    {
                        throw new Exception("You have to provide the index for the InsertTo mode.");
                    }

                    cmp.PreventRenderTo = true;
                    break;
                }

                Page pageHolder = null;
                bool isLazy     = this.Control.IsLazy;
                this.Control.IsDynamicLazy = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo);
                Control parent = null;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering  = true;
                this.Control.ForceLazy         = forceLazy;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager(true);
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles  = ResourceLocationType.None;
                    newMgr.IDMode        = IDMode.Explicit;
                    newMgr.IsDynamic     = true;
                    pageHolder.Controls.Add(newMgr);
                    this.ResourceManager = newMgr;

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl <ResourceManager>(pageHolder);
                    this.ResourceManager = newMgr;
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                if (this.Control.ClientID.IsNotEmpty() && !this.Control.IsGeneratedID)
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

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

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

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

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    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();
                    }
                }

                string methodTemplate = string.Concat(".", method ?? "add", "(");

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = string.Concat(".", method ?? "insert", "(", index.Value, ",");
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control) && isLazy)
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);

                            string initScript = c.BuildInitScript();

                            if (selfRendering)
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript.ConcatWith(initScript.EndsWith(";") ? "" : ";", parent.ClientID.ConcatWith(methodTemplate, c.ClientID, ");")));
                            }
                            else
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, c.ParentComponent.ClientID.ConcatWith(methodTemplate, initScript, ");"));
                            }

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        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;

                        foreach (KeyValuePair <long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    var elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Append(elementGet.ConcatWith(methodTemplate, this.Control.ForceLazy ? this.Control.ConfigID : this.Control.ClientID, ");"));
                }

                foreach (KeyValuePair <long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            this.Control.ForceLazy = false;

            return(Transformer.NET.Html.HtmlTransformer.Transform(this.script));
        }
Пример #8
0
        public virtual string Build(RenderMode mode, string element, int?index, bool selfRendering, bool forceResources)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                Component cmp = this.Control as Component;

                switch (mode)
                {
                case RenderMode.RenderTo:
                    if (cmp == null)
                    {
                        throw new Exception("RenderTo mode can be applied to only a Component.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        throw new Exception("You must specify an element for RenderTo mode.");
                    }

                    if (this.Control.IsLazy)
                    {
                        throw new Exception("Lazy control can be rendered with Automatic render mode only.");
                    }

                    cmp.RenderTo = element;

                    break;

                case RenderMode.AddTo:
                case RenderMode.InsertTo:
                    if (cmp == null)
                    {
                        throw new Exception("AddTo mode can be applied to only a Component.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        throw new Exception("You must specify an Element for the AddTo mode.");
                    }

                    if (this.Control.IsLazy)
                    {
                        //throw new Exception("Lazy controls can be rendered in Automatic mode only.");
                    }

                    if (mode == RenderMode.InsertTo && index == null)
                    {
                        throw new Exception("You have to provide the index for the InsertTo mode.");
                    }

                    cmp.AutoRender = false;
                    break;
                }

                Page pageHolder = null;
                bool isLazy     = this.Control.IsLazy;
                this.Control.IsDynamicLazy = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo);
                Control parent = null;// this.Control.ParentComponentNotLayout;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering  = true;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager();
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles  = ResourceLocationType.None;
                    newMgr.IDMode        = IDMode.Client;
                    newMgr.IsDynamic     = true;
                    pageHolder.Controls.Add(newMgr);

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = ControlUtils.FindControl <ResourceManager>(pageHolder);

                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                List <XControl> childControls = this.FindControls(this.Control, selfRendering, sb, null);
                childControls.Insert(0, this.Control);

                /*
                 * foreach (XControl c in childControls)
                 * {
                 *  if (c.Visible || Object.ReferenceEquals(c, this.Control))
                 *  {
                 *      c.EnsureDynamicID();
                 *
                 *      foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                 *      {
                 *          if (proxyScript.Value.IsNotEmpty())
                 *          {
                 *              this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                 *          }
                 *      }
                 *
                 *      c.ProxyScripts.Clear();
                 *  }
                 * }
                 *
                 * foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                 * {
                 *  sb.Append(script.Value);
                 * }
                 *
                 * this.ScriptOnReadyBag.Clear();
                 */
                if (this.Control.ClientID.IsNotEmpty())
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

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

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

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

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

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

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

                    childControls = newChildControls;
                }

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

                string methodTemplate = ".addAndDoLayout(";

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = ".insertAndDoLayout({0},".FormatWith(index.Value);
                }

                foreach (XControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.EnsureDynamicID();

                        if (Object.ReferenceEquals(c, this.Control) && isLazy)
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);

                            string initScript = c.BuildInitScript();

                            if (selfRendering)
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript.ConcatWith(initScript.EndsWith(";") ? "" : ";", parent.ClientID.ConcatWith(methodTemplate, c.ClientID, ");")));
                            }
                            else
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, c.ParentComponentNotLayout.ClientID.ConcatWith(methodTemplate, initScript, ");"));
                            }

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        else
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID, c.BuildInitScript());
                        }

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair <long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    sb.Append(element.ConcatWith(methodTemplate, this.Control.ClientID, ");"));
                }

                foreach (KeyValuePair <long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            return(this.script);
        }
        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))
                    {
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                SelfRenderingPage pageHolder = new SelfRenderingPage();
                ResourceManager newMgr = new ResourceManager(true);
                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles = ResourceLocationType.None;
                newMgr.IDMode = IDMode.Explicit;
                newMgr.IsDynamic = true;
                pageHolder.Controls.Add(newMgr);
                pageHolder.Controls.Add(this.Control);
                pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();

                string html = this.Control is INoneContentable ? null : BaseScriptBuilder.RenderControl(this.Control, pageHolder);
                pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;

                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]);
                    }
                }                
                
                string  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();
            }

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

            return config;
        }
Пример #10
0
        public virtual string Build(bool selfRendering, bool forceResources)
        {
            this.ForceResources = forceResources;
            if (this.script == null)
            {
                Page pageHolder = null;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering = true;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager rm = new ResourceManager();
                    rm.RenderScripts = ResourceLocationType.None;
                    rm.RenderStyles = ResourceLocationType.None;
                    rm.IDMode = IDMode.Client;
                    rm.IsDynamic = true;
                    pageHolder.Controls.Add(rm);

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl<ResourceManager>(pageHolder);
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                this.Control.ContentUpdated = this.Control.HasContent();
                ContainerBase container = this.Control as ContainerBase;
                if (container != null && container.Items.Count > 0)
                {
                    sb.AppendFormat("{0}.removeAll();", this.Control.ClientID);
                }

                List<XControl> childControls = this.FindControls(this.Control, selfRendering, sb, null);

                foreach (XControl c in childControls)
                {
                    if (c.Visible)
                    {
                        c.DeferInitScriptGeneration = selfRendering;
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

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

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

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

                    childControls = newChildControls;
                }

                foreach (XControl c in childControls)
                {
                    if (c.Visible)
                    {
                        c.OnClientInit(true);
                        c.RegisterBeforeAfterScript();
                    }
                }

                foreach (XControl c in childControls)
                {
                    if (c.Visible)
                    {
                        string initScript = c.BuildInitScript();
                        if (!string.IsNullOrEmpty(initScript))
                        {
                            if (this.layoutItems.Contains(c))
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, this.Control.ClientID.ConcatWith(".add(", initScript, ");"));
                            }
                            else
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript);
                            }
                        }

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                //if (selfRendering)
                //{
                //    this.RegisterHtml(sb, pageHolder);
                //}

                if (container != null && container.Items.Count > 0)
                {
                    sb.AppendFormat("{0}.doLayout();", this.Control.ClientID);
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            return this.script;
        }
Пример #11
0
        public static string RenderControl(Control control, Page pageHolder)
        {
            if (pageHolder == null)
            {
                pageHolder = new SelfRenderingPage();
                pageHolder.Controls.Add(control);
            }

            StringWriter output = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, output, true);

            StringBuilder sb = new StringBuilder();
            //MatchCollection mc = Regex.Matches(output.ToString(), string.Concat(XControl.TOP_DYNAMIC_CONTROL_TAG_S, "(.*?)", XControl.TOP_DYNAMIC_CONTROL_TAG_E), RegexOptions.Singleline);
            MatchCollection mc = TopDynamic_RE.Matches(output.ToString());

            foreach (Match m in mc)
            {
                sb.Append(m.Groups[1].Value);
            }

            return sb.ToString() ?? "";
        }
Пример #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual string SelfRender()
        {
            if (HttpContext.Current == null)
            {
                return "";
            }
            
            SelfRenderingPage pageHolder = new SelfRenderingPage();

            if (!(this is ResourceManager))
            {
                ResourceManager newMgr = new ResourceManager();

                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles = ResourceLocationType.None;
                newMgr.IDMode = IDMode.Explicit;
                newMgr.IsSelfRender = true;            
                newMgr.IsDynamic = true;
                pageHolder.Controls.Add(newMgr);                
            }

            this.IsSelfRender = true;            
            this.IDMode = IDMode.Explicit;               
            
            pageHolder.Controls.Add(this);

            StringWriter output = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, output, true);
#if MVC            
            this.IsSelfRender = this is Ext.Net.MVC.MvcResourceManager;
#else
            this.IsSelfRender = false;
#endif


            return output.ToString();
        }
Пример #13
0
        public virtual string Build(RenderMode mode, string element, int? index, bool selfRendering, bool forceResources)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                Component cmp = this.Control as Component;

                switch (mode)
                {
                    case RenderMode.RenderTo:
                        if (cmp == null)
                        {
                            throw new Exception("RenderTo mode can be applied to only a Component.");
                        }

                        if (string.IsNullOrEmpty(element))
                        {
                            throw new Exception("You must specify an element for RenderTo mode.");
                        }

                        if (this.Control.IsLazy)
                        {
                            throw new Exception("Lazy control can be rendered with Automatic render mode only.");
                        }

                        cmp.RenderTo = element;

                        break;
                    case RenderMode.AddTo:
                    case RenderMode.InsertTo:
                        if (cmp == null)
                        {
                            throw new Exception("AddTo mode can be applied to only a Component.");
                        }

                        if (string.IsNullOrEmpty(element))
                        {
                            throw new Exception("You must specify an Element for the AddTo mode.");
                        }

                        if (this.Control.IsLazy)
                        {
                            //throw new Exception("Lazy controls can be rendered in Automatic mode only.");
                        }

                        if (mode == RenderMode.InsertTo && index == null)
                        {
                            throw new Exception("You have to provide the index for the InsertTo mode.");
                        }

                        cmp.AutoRender = false;
                        break;
                }

                Page pageHolder = null;
                bool isLazy = this.Control.IsLazy;
                this.Control.IsDynamicLazy = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo);
                Control parent = null;// this.Control.ParentComponentNotLayout;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering = true;

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager();
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles = ResourceLocationType.None;
                    newMgr.IDMode = IDMode.Client;
                    newMgr.IsDynamic = true;
                    pageHolder.Controls.Add(newMgr);

                    pageHolder.Controls.Add(this.Control);   
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = ControlUtils.FindControl<ResourceManager>(pageHolder);

                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                List<XControl> childControls = this.FindControls(this.Control, selfRendering, sb, null);
                childControls.Insert(0, this.Control);
                /*
                foreach (XControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.EnsureDynamicID();

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);                                
                            }
                        }
                        
                        c.ProxyScripts.Clear();
                    }
                }

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                this.ScriptOnReadyBag.Clear();
                */
                if (this.Control.ClientID.IsNotEmpty())
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

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

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

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

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

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

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

                    childControls = newChildControls;
                }

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

                string methodTemplate = ".addAndDoLayout(";

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = ".insertAndDoLayout({0},".FormatWith(index.Value);
                }

                foreach (XControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.EnsureDynamicID();

                        if (Object.ReferenceEquals(c, this.Control) && isLazy)
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);
                            
                            string initScript = c.BuildInitScript();                            

                            if (selfRendering)
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript.ConcatWith(initScript.EndsWith(";") ? "" : ";", parent.ClientID.ConcatWith(methodTemplate, c.ClientID, ");")));
                            }
                            else
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, c.ParentComponentNotLayout.ClientID.ConcatWith(methodTemplate, initScript, ");"));
                            }

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        else
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID, c.BuildInitScript());
                        }
                        
                        c.AlreadyRendered = true;

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    sb.Append(element.ConcatWith(methodTemplate, this.Control.ClientID, ");"));
                }

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            return this.script;
        }
        public virtual string Build(bool selfRendering, bool forceResources)
        {
            this.ForceResources = forceResources;
            if (this.script == null)
            {
                Page pageHolder = null;
                this.Control.TopDynamicControl = true;
                this.Control.ForceIdRendering = true;
                this.ResourceManager = Ext.Net.ResourceManager.GetInstance();

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager rm = new ResourceManager(true);
                    rm.RenderScripts = ResourceLocationType.None;
                    rm.RenderStyles = ResourceLocationType.None;
                    rm.IDMode = IDMode.Explicit;
                    rm.IsDynamic = true;
                    pageHolder.Controls.Add(rm);
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = rm;
                    }

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl<ResourceManager>(pageHolder);
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                this.Control.ContentUpdated = this.Control.HasContent();
                AbstractContainer container = this.Control as AbstractContainer;
                if (container != null)
                {
                    sb.AppendFormat("{0}.removeAll();", this.Control.ClientID);
                }

                List<BaseControl> childControls = this.FindControls(this.Control, selfRendering, sb, null, null);

                if (selfRendering && pageHolder != null)
                {
                    pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible)
                    {                        
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    if (pageHolder != null)
                    {
                        pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;
                    }

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

                    if (this.Control.AutoDataBind)
                    {
                        this.Control.DataBind();
                    }

                    foreach (BaseControl c in newChildControls)
                    {
                        if (!childControls.Contains(c) && c.Visible)
                        {
                            if (c.AutoDataBind)
                            {
                                c.DataBind();
                            }
                        }
                    }

                    childControls = newChildControls;
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible)
                    {
                        c.OnClientInit(true);
                        c.RegisterBeforeAfterScript();
                    }
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible)
                    {
                        string initScript = c.BuildInitScript();
                        if (!string.IsNullOrEmpty(initScript))
                        {   if (this.layoutItems.Contains(c))
                            {
                                this.ScriptClientInitBag.Add(c.ClientInitID, this.Control.ClientID.ConcatWith(".add(", initScript, ");"));
                            }
                            else
                            {
                                initScript = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary<string, string>{                        
                                                {"ref", c.IsLazy ? c.ClientInitID : "init_script"},
                                                {"index", ResourceManager.ScriptOrderNumber.ToString()}
                                            }, initScript);    
                                this.ScriptClientInitBag.Add(c.ClientInitID, initScript);
                            }
                        }

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }
               
                if (container != null && container.Items.Count > 0)
                {
                    sb.AppendFormat("{0}.doLayout();", this.Control.ClientID);
                }

                sb.Append(Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary<string, string>{                        
                                                {"id", "init_script"}                            
                                            }));
                this.script = this.RegisterResources(sb.ToString());
            }

            return Transformer.NET.Html.HtmlTransformer.Transform(this.script);
        }
Пример #15
0
        public virtual string Build(RenderMode mode, string element, int?index, bool selfRendering, bool forceResources, string method, bool forceLazy, bool clearContainer)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                bool isLazy = this.Control.IsLazy;

                if (mode == RenderMode.Auto)
                {
                    mode = isLazy ? RenderMode.AddTo : RenderMode.RenderTo;
                }

                switch (mode)
                {
                case RenderMode.RenderTo:
                    if (cmp != null)
                    {
                        if (string.IsNullOrEmpty(element))
                        {
                            element = TokenUtils.RawWrap("Ext.net.ResourceMgr.getRenderTarget()");
                        }

                        if (this.Control.IsLazy)
                        {
                            throw new Exception("Lazy control cannot be rendered with RenderTo mode.");
                        }

                        cmp.RenderTo = element;
                    }
                    break;

                case RenderMode.AddTo:
                case RenderMode.Replace:
                case RenderMode.InsertTo:
                    if (cmp == null)
                    {
                        throw new Exception("AddTo mode can be applied to only a AbstractComponent.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        if (isLazy)
                        {
                            element = this.Control.ParentComponent.ClientID;
                        }
                        else
                        {
                            throw new Exception("You must specify an Element for the AddTo mode.");
                        }
                    }

                    if (mode == RenderMode.InsertTo && index == null)
                    {
                        throw new Exception("You have to provide the index for the InsertTo mode.");
                    }

                    cmp.PreventRenderTo = true;
                    break;
                }

                Page pageHolder = null;
                this.Control.IsDynamicLazy     = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo || mode == RenderMode.Replace);
                this.Control.TopDynamicControl = true;
                //this.Control.ForceIdRendering = true;
                this.Control.ForceLazy = forceLazy || this.Control.IsDynamicLazy;
                this.ResourceManager   = Ext.Net.ResourceManager.GetInstance();

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager(true);
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles  = ResourceLocationType.None;
                    newMgr.IDMode        = IDMode.Explicit;
                    newMgr.IsDynamic     = true;
                    pageHolder.Controls.Add(newMgr);

                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl <ResourceManager>(pageHolder);
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                if (this.Control.ClientID.IsNotEmpty() && !this.Control.IsGeneratedID)
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

                if (clearContainer)
                {
                    if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                    {
                        string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                        sb.AppendFormat("{0}.removeAll();", elementGet);
                    }
                    else if (mode != RenderMode.Replace)
                    {
                        sb.AppendFormat("Ext.net.getEl(\"{0}\").update();", element);
                    }
                }

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

                if (selfRendering && pageHolder != null)
                {
                    pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();
                }

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

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    if (pageHolder != null)
                    {
                        pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;
                    }

                    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();
                    }
                }

                string methodTemplate = string.Concat(".", method ?? "add", "(");

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = string.Concat(".", method ?? "insert", "(", index.Value, ",");
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control) && (this.Control.IsLazy || this.Control.ForceLazy))
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);

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

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        else
                        {
                            string tokenValue = ((c is LazyObservable && c.IsIdRequired) ? "window.{0}=".FormatWith(c.ClientID) : "") + c.BuildInitScript();
                            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() }
                            }, tokenValue);

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

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair <long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

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

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Append(elementGet.ConcatWith(methodTemplate, topAnchor, ");"));
                }
                else if (mode == RenderMode.Replace)
                {
                    sb.Append("Ext.net._renderTo(arguments[0],".ConcatWith(topAnchor, ");"));
                }

                foreach (KeyValuePair <long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                if (mode == RenderMode.Replace)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Insert(0, elementGet + ".replace(function(){");
                    sb.Append("});");
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            this.Control.ForceLazy = false;

            return(Transformer.NET.Html.HtmlTransformer.Transform(this.script));
        }
Пример #16
0
        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))
                    {
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                SelfRenderingPage pageHolder = new SelfRenderingPage();
                ResourceManager   newMgr     = new ResourceManager(true);
                newMgr.RenderScripts = ResourceLocationType.None;
                newMgr.RenderStyles  = ResourceLocationType.None;
                newMgr.IDMode        = IDMode.Explicit;
                newMgr.IsDynamic     = true;
                pageHolder.Controls.Add(newMgr);
                pageHolder.Controls.Add(this.Control);
                pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();

                string html = this.Control is INoneContentable ? null : BaseScriptBuilder.RenderControl(this.Control, pageHolder);
                pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;

                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]);
                    }
                }

                string 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();
            }

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

            return(config);
        }
Пример #17
0
        public virtual string Build(RenderMode mode, string element, int? index, bool selfRendering, bool forceResources, string method, bool forceLazy, bool clearContainer)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                bool isLazy = this.Control.IsLazy;

                if (mode == RenderMode.Auto)
                {
                    mode = isLazy ? RenderMode.AddTo : RenderMode.RenderTo;                    
                }                

                switch (mode)
                {
                    case RenderMode.RenderTo:
                        if (cmp != null)
                        {
                            if (string.IsNullOrEmpty(element))
                            {
                                element = TokenUtils.RawWrap("Ext.net.ResourceMgr.getRenderTarget()");
                            }

                            if (this.Control.IsLazy)
                            {
                                throw new Exception("Lazy control cannot be rendered with RenderTo mode.");
                            }

                            cmp.RenderTo = element;
                        }
                        break;
                    case RenderMode.AddTo:
                    case RenderMode.Replace:
                    case RenderMode.InsertTo:
                        if (cmp == null)
                        {
                            throw new Exception("AddTo mode can be applied to only a AbstractComponent.");
                        }

                        if (string.IsNullOrEmpty(element))
                        {
                            if (isLazy)
                            {
                                element = this.Control.ParentComponent.ClientID;
                            }
                            else
                            {
                                throw new Exception("You must specify an Element for the AddTo mode.");
                            }
                        }

                        if (mode == RenderMode.InsertTo && index == null)
                        {
                            throw new Exception("You have to provide the index for the InsertTo mode.");
                        }

                        cmp.PreventRenderTo = true;
                        break;
                }

                Page pageHolder = null;                
                this.Control.IsDynamicLazy = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo || mode == RenderMode.Replace);
                this.Control.TopDynamicControl = true;
                //this.Control.ForceIdRendering = true;
                this.Control.ForceLazy = forceLazy || this.Control.IsDynamicLazy;
                this.ResourceManager = Ext.Net.ResourceManager.GetInstance();

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager(true);
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles = ResourceLocationType.None;
                    newMgr.IDMode = IDMode.Explicit;
                    newMgr.IsDynamic = true;
                    pageHolder.Controls.Add(newMgr);
                    
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }

                    pageHolder.Controls.Add(this.Control);   
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl<ResourceManager>(pageHolder);
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                if (this.Control.ClientID.IsNotEmpty() && !this.Control.IsGeneratedID)
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

                if (clearContainer)
                {
                    if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                    {
                        string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                        sb.AppendFormat("{0}.removeAll();", elementGet);
                    }
                    else if(mode != RenderMode.Replace)
                    {
                        sb.AppendFormat("Ext.net.getEl(\"{0}\").update();", element);
                    }
                }

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

                if (selfRendering && pageHolder != null)
                {
                    pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();
                }
                
                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    if (pageHolder != null)
                    {
                        pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;
                    }

                    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();
                    }
                }

                string methodTemplate = string.Concat(".",method ?? "add","(");

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = string.Concat(".", method ?? "insert", "(", index.Value, ",");
                }               
                
                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control) && (this.Control.IsLazy || this.Control.ForceLazy))
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);
                            
                            string initScript = c.BuildInitScript();
                            string topScript = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary<string, string>{                        
                                                {"ref", "top_dynamic_control"},
                                                {"index", ResourceManager.ScriptOrderNumber.ToString()}
                                            }, initScript);
                            this.ScriptClientInitBag.Add(c.ClientInitID, topScript);
                            
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        else
                        {
                            string tokenValue = ((c is LazyObservable && c.IsIdRequired) ? "window.{0}=".FormatWith(c.ClientID) : "") + c.BuildInitScript();
                            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()}
                                            }, tokenValue);

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

                        foreach (KeyValuePair<long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

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

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

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

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Append(elementGet.ConcatWith(methodTemplate, topAnchor, ");"));
                }
                else if (mode == RenderMode.Replace)
                {
                    sb.Append("Ext.net._renderTo(arguments[0],".ConcatWith(topAnchor, ");"));
                }

                foreach (KeyValuePair<long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                if (mode == RenderMode.Replace)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Insert(0, elementGet + ".replace(function(){");
                    sb.Append("});");
                }
                
                this.script = this.RegisterResources(sb.ToString());
            }

            this.Control.ForceLazy = false;

            return Transformer.NET.Html.HtmlTransformer.Transform(this.script);
        }