Beispiel #1
0
        public static string ToHTML(HtmlControl Ctrl)
        {
            StringWriter   SW         = new StringWriter();
            HtmlTextWriter HTMLWriter = new HtmlTextWriter(SW);

            Ctrl.RenderControl(HTMLWriter);
            return(SW.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// HTMLs the control to string.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        internal static string HtmlControlToString(HtmlControl control)
        {
            StringWriter writer = new StringWriter(new StringBuilder());

            control.RenderControl(new HtmlTextWriter(writer));

            return(JavaScriptSerializer.Serialize(writer.ToString()));
        }
        public static string ToHtml(this HtmlControl control)
        {
            System.IO.StringWriter sw  = new System.IO.StringWriter();
            HtmlTextWriter         htw = new HtmlTextWriter(sw);

            control.RenderControl(htw);
            return(sw.ToString());
        }
    // The loaded document MUST have a script similar to this

    //		<script type="text/javascript" >
    //				function appendHtml(o) {
    //				var div = document.createElement("div");
    //				div.innerHTML = o;
    //				document.body.appendChild( div);
    //				}
    //		</script>


    public static void InsertHtmlControl(HtmlControl c, WebBrowser wb)
    {
        // create a HtmlTextWriter;
        StringBuilder  sb    = new StringBuilder();
        StringWriter   sw    = new StringWriter(sb);
        HtmlTextWriter htmlw = new HtmlTextWriter(sw);

        // render the control as html
        c.RenderControl(htmlw);


        //invoke the script passing in the html
        object[] p = new object[1];
        p[0] = (object)sb.ToString();
        wb.Document.InvokeScript("appendHtml", p);

        htmlw.Close();
        htmlw.Dispose();

        sw.Dispose();
    }
        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (this.DesignMode)
            {
                return;
            }

            if (this.ProcessCertificateDownloadRequest())
            {
                return;
            }

            string divId = string.Format(CultureInfo.InvariantCulture, "{0}_div", this.ID);

            HtmlGenericControl container = new HtmlGenericControl("div")
            {
                ID = divId
            };

            ClientScriptManager clientScriptManager = this.Page.ClientScript;
            HtmlImage           controlImage        = new HtmlImage
            {
                ID  = string.Format(CultureInfo.CurrentUICulture, "STVC{0}", Guid.NewGuid()),
                Src = clientScriptManager.GetWebResourceUrl(typeof(SecurityTokenVisualizerControl), "Microsoft.Samples.DPE.Identity.Controls.Content.images.icon.png"),
                Alt = Resources.SecurityTokenVisualizer,
            };

            controlImage.Attributes["title"] = Resources.SecurityTokenVisualizer;

            HtmlControl tokenVisualizerHeader = this.CreateCollapsableHeader(controlImage, container, false /* Expanded as Default */);

            if (this.Font == null || string.IsNullOrEmpty(this.Font.Name))
            {
                container.Style["font-family"]             = "Arial, Consolas, Segoe UI";
                tokenVisualizerHeader.Style["font-family"] = "Arial, Consolas, Segoe UI";
            }
            if (this.Font == null || this.Font.Size.IsEmpty)
            {
                container.Style["font-size"]             = "small";
                tokenVisualizerHeader.Style["font-size"] = "small";
            }

            var containerRounded = this.AddContainerRounded(container);

            if (Thread.CurrentPrincipal.Identity.IsAuthenticated && Thread.CurrentPrincipal.Identity is IClaimsIdentity)
            {
                AddClaimsTable(containerRounded);
                containerRounded.Controls.Add(new HtmlGenericControl()
                {
                    InnerHtml = "&nbsp;"
                });
                this.AddSamlTokenTable(containerRounded);
            }
            else
            {
                AddNotAuthenticatedUserTable(containerRounded);
            }

            tokenVisualizerHeader.RenderControl(writer);

            container.RenderControl(writer);

            base.RenderContents(writer);
        }
 public string GetControlRenderString(HtmlControl control)
 {
     System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
     control.RenderControl(new HtmlTextWriter(new StringWriter(strBuilder)));
     return(strBuilder.ToString());
 }