Example #1
0
 public NamedTemplate(ViewContext viewContext, string name)
 {
     _globals = GlobalOptions.Get(viewContext.HttpContext);
     _writer  = new TemplateWriter(viewContext.Writer);
     if (_globals.InTemplate())
     {
         throw new InvalidOperationException("A named template cannot be defined inside any template.");
     }
     _writer.WriteStart(name);
     _globals.EnterTemplate();
 }
Example #2
0
        public void RenderWithStaticMarkup(StringBuilder builder)
        {
            string @static = ElementID.GetStatic();

            builder.Append("<div id=\"").Append(WebUtility.HtmlEncode(@static)).Append("\">")
            .Append(TranscludedContent)
            .Append("</div>");
            if (Templates != null)
            {
                using (StringWriter htmlWriter = new StringWriter(builder))
                {
                    TemplateWriter templateWriter = new TemplateWriter(htmlWriter);
                    foreach (Tuple <string, string> template in Templates)
                    {
                        templateWriter.WriteTemplate(template.Item1, template.Item2);
                    }
                }
            }
            RenderStartupScriptOpenTag(builder, RequireStartupScriptID ? @static : null);
            bool useJQueryReady = Compatibility.Rendering.UseJQueryReady;

            if (useJQueryReady)
            {
                builder.Append("jQuery(function($){");
            }
            else
            {
                builder.Append("DevExpress.utils.readyCallbacks.add((function($){");
            }
            builder.Append(FormatJQueryByID(@static)).Append(".").Append(PluginName)
            .Append("(")
            .Append(JsonUtils.SafeSerialize(Options))
            .Append(")");
            RenderValidator(builder);
            if (useJQueryReady)
            {
                builder.Append(";})");
            }
            else
            {
                builder.Append(";}).bind(this, jQuery))");
            }
            builder.Append(";</script>");
        }