Exemple #1
0
        protected override void InstantiateControlIn(HtmlControl container)
        {
            if (RenderWebResourcesInline == true)
            {
                var context = CrmConfigurationManager.CreateContext(ContextName);

                var webResource =
                    context.CreateQuery("webresource").FirstOrDefault(
                        wr => wr.GetAttributeValue <string>("name") == Metadata.WebResourceUrl);

                if (webResource == null || string.IsNullOrWhiteSpace(webResource.GetAttributeValue <string>("content")))
                {
                    var placeholder = new HtmlGenericControl("literal")
                    {
                        ID = Metadata.ControlID, Visible = Enabled
                    };

                    container.Controls.Add(placeholder);

                    return;
                }

                var htmlContent = new HtmlDocument();

                var webResourceContent = DecodeFrom64(webResource.GetAttributeValue <string>("content"));

                htmlContent.LoadHtml(webResourceContent);

                var body = htmlContent.DocumentNode.SelectSingleNode("//body");

                var literal = new HtmlGenericControl("literal")
                {
                    ID = Metadata.ControlID, Visible = Enabled
                };

                if (body != null)
                {
                    literal.InnerHtml = body.InnerHtml;

                    container.Controls.Add(literal);
                }
            }
            else
            {
                var iframe = new HtmlGenericControl("iframe")
                {
                    ID = Metadata.ControlID, Visible = Enabled
                };

                iframe.Attributes["src"]         = WebResourceRouteFormat.FormatWith(Metadata.WebResourceUrl);
                iframe.Attributes["scrolling"]   = Metadata.WebResourceScrolling;
                iframe.Attributes["frameborder"] = Metadata.WebResourceBorder ? "1" : "0";
                iframe.Attributes["height"]      = "100%";
                iframe.Attributes["width"]       = "100%";

                container.Controls.Add(iframe);
            }
        }
Exemple #2
0
        protected override void InstantiateControlIn(HtmlControl container)
        {
            var image = new HtmlImage
            {
                ID      = Metadata.ControlID,
                Alt     = Metadata.WebResourceAltText,
                Src     = WebResourceRouteFormat.FormatWith(Metadata.WebResourceUrl),
                Visible = Enabled
            };

            image.Attributes["class"] = CssClass;
            container.Attributes.CssStyle["text-align"]     = Metadata.WebResourceHorizontalAlignment;
            container.Attributes.CssStyle["vertical-align"] = Metadata.WebResourceVerticalAlignment;

            if (Metadata.WebResourceSizeType == "Specific")
            {
                image.Height = Metadata.WebResourceHeight.GetValueOrDefault();
                image.Width  = Metadata.WebResourceWidth.GetValueOrDefault();
            }

            container.Controls.Add(image);
        }