RenderControl() public method

public RenderControl ( System.Web.UI.HtmlTextWriter writer ) : void
writer System.Web.UI.HtmlTextWriter
return void
Example #1
0
 private static void ExportControl(Control control, JsonWriter writer)
 {
     StringWriter innerWriter = new StringWriter();
     HtmlTextWriter htmlWriter = GetHtmlWriter(innerWriter);
     control.RenderControl(htmlWriter);
     writer.WriteString(innerWriter.ToString());
 }
 private static void FormatControl(Control control, JsonWriter writer)
 {
     StringWriter stringWriter = new StringWriter();
     HtmlTextWriter htmlWriter = GetHtmlWriter(stringWriter);
     control.RenderControl(htmlWriter);
     writer.WriteString(stringWriter.ToString());
 }
Example #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Visible)
            {
                var assets = AspNetAssets.EnsureCurrentAssets();
                if (!string.IsNullOrEmpty(Src))
                {
                    RegisterLink(assets, Src);
                }

                var inlineTemplate = GetInlineTemplate();
                if (inlineTemplate != null)
                {
                    using (var textWriter = new StringWriter())
                    {
                        using (var htmlTextWriter = new HtmlTextWriter(textWriter))
                        {
                            var control = new Control();
                            inlineTemplate.InstantiateIn(control);
                            control.RenderControl(htmlTextWriter);
                        }
                        var inline = textWriter.ToString();
                        if (!string.IsNullOrEmpty(inline.Trim()))
                        {
                            RegisterInline(assets, inline);
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary> 
        /// 将Web控件导出 
        /// </summary> 
        /// <param name="source">控件实例</param> 
        /// <param name="type">类型:Excel或Word</param> 
        public static void ExpertControl(Control source, string filename, DocumentType type)
        {
            //设置Http的头信息,编码格式 
            if (type == DocumentType.Excel)
            {
                //Excel 
                HttpContext.Current.Response.AppendHeader("Content-Disposition",
                                                          "attachment;filename=" + filename + ".xls");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
            }
            else if (type == DocumentType.Word)
            {
                //Word 
                HttpContext.Current.Response.AppendHeader("Content-Disposition",
                                                          "attachment;filename=" + filename + ".doc");
                HttpContext.Current.Response.ContentType = "application/ms-word";
            }
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

            //关闭控件的视图状态 
            source.Page.EnableViewState = false;

            //初始化HtmlWriter 
            var writer = new StringWriter();
            var htmlWriter = new HtmlTextWriter(writer);
            source.RenderControl(htmlWriter);

            //输出 
            HttpContext.Current.Response.Write(writer.ToString());
            HttpContext.Current.Response.End();
        }
Example #5
0
 public string GetControlsHTML(Control c)
 {
     System.IO.StringWriter sw = new System.IO.StringWriter();
     HtmlTextWriter hw = new HtmlTextWriter(sw);
     c.RenderControl(hw);
     return sw.ToString();
 }
Example #6
0
 public static string ControlString(Control control)
 {
     StringWriter sw = new StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     control.RenderControl(htw);
     return sw.ToString();
 }
Example #7
0
 public static string RenderControlToString(Control c)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
     c.RenderControl(htmlWriter);
     return sb.ToString();
 }
Example #8
0
 public static string RenderControlToString(Control ctr)
 {
     var sb = new StringBuilder();
     var writer = new StringWriter(sb);
     var writer2 = new HtmlTextWriter(writer);
     ctr.RenderControl(writer2);
     return sb.ToString();
 }
 public static string GetControlRendering(Control c, bool designMode) {
     if (designMode) {
         c.Site = new DesignModeSite();
     }
     HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
     c.RenderControl(writer);
     return writer.InnerWriter.ToString();
 }
		private string RenderCtrl(Control ctrl) {
			StringWriter sw = new StringWriter();
			HtmlTextWriter tw = new HtmlTextWriter(sw);

			ctrl.RenderControl(tw);

			return sw.ToString();
		}
Example #11
0
        public static string RenderControl(Control ctrl)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            ctrl.RenderControl(hw);
            return sb.ToString();
        }
Example #12
0
        private string RenderControl(Control control)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter writer = new HtmlTextWriter(sw);

            control.RenderControl(writer);
            return sb.ToString();
        }
Example #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fileName">no extension needed here</param>
 /// <param name="ctl"></param>
 /// <param name="preProcess">whether to process the control for those elements that is not supported in excel</param>
 public static void ExportControl(string fileName, Control ctl, bool preProcess)
 {
     using (StringWriter sw = new StringWriter())
     using (HtmlTextWriter htw = new HtmlTextWriter(sw)) {
         if (preProcess)
             PrepareControlForExport(ctl);
         ctl.RenderControl(htw);
         ExportString(fileName, sw.ToString());
     }
 }
        private static void ExportControl(Control control, JsonWriter writer)
        {
            Debug.Assert(control != null);
            Debug.Assert(writer != null);

            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter = GetHtmlWriter(stringWriter);
            control.RenderControl(htmlWriter);
            writer.WriteString(stringWriter.ToString());
        }
Example #15
0
 public static string GetRenderResult(Control control)
 {
     using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
     {
         using (HtmlTextWriter writer = new HtmlTextWriter(sw))
             control.RenderControl(writer);
         sw.WriteLine();
         return sw.ToString();
     }
 }
Example #16
0
        public static string RenderControl(Control control)
        {
            using (var writer = new StringWriter())
            using (var htmlWriter = new HtmlTextWriter(writer))
            {
                control.RenderControl(htmlWriter);
                htmlWriter.Flush();

                return writer.ToString();
            }
        }
Example #17
0
        public static string RenderControl(Control control)
        {
            using (StringWriter stringWriter = new StringWriter())
            using (XhtmlTextWriter htmlTextWriter = new XhtmlTextWriter(stringWriter))
            {
                control.RenderControl(htmlTextWriter);

                return _collapseMultipleLinefeeds.Replace(HttpUtility.HtmlDecode(stringWriter.ToString())
                                         .Trim(Environment.NewLine.ToArray()), Environment.NewLine); // Replace multiple linefeeds with single.
            }
        }
        public static IHtmlString RenderControl(this HtmlHelper html, Control control)
        {
            StringBuilder sb = new StringBuilder();
            using (StringWriter textwriter = new StringWriter(sb))
            {
                HtmlTextWriter htmlWriter = new HtmlTextWriter(textwriter);
                control.RenderControl(htmlWriter);
            }

           return html.Raw(sb);
        }
        public static string RenderControl(Control control)
        {
            var tw = new StringWriter();

            // *** Simple rendering - just write the control to the text writer
            // *** works well for single controls without containers
            var writer = new Html32TextWriter(tw);
            control.RenderControl(writer);
            writer.Close();

            return tw.ToString();
        }
Example #20
0
 /// <summary>
 /// Calls the render method of all the Controls in a control tree,
 /// but instead of rendering to the response stream, we render to an
 /// in-memory string stream and then return that.
 /// </summary>
 /// <param name="control"></param>
 /// <returns></returns>
 public static string RenderControlToString(Control control)
 {
     StringBuilder sb = new StringBuilder(512);
     using (StringWriter stringWriter = new StringWriter(sb))
     {
         using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
         {
             control.RenderControl(htmlWriter);
         }
     }
     return sb.ToString();
 }
Example #21
0
    public void exportGridToExcel(Control ctl)
    {
        string attachment = "attachment; filename=etrack_excel_export.xls";
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);

        ctl.RenderControl(htextw);
        HttpContext.Current.Response.Write(stw.ToString());
        HttpContext.Current.Response.End();
    }
Example #22
0
 //导出数据excel(控件中的内容)
 private void ReportToExcel(Control ctl, string FileName)
 {
     HttpContext.Current.Response.Charset = "UTF-8";
     HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
     HttpContext.Current.Response.ContentType = "application/ms-excel";
     HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
     ctl.EnableViewState = false;
     System.IO.StringWriter tw = new System.IO.StringWriter();
     HtmlTextWriter hw = new HtmlTextWriter(tw);
     ctl.RenderControl(hw);
     HttpContext.Current.Response.Write(tw.ToString());
     HttpContext.Current.Response.End();
 }
Example #23
0
 /// <summary>
 ///     datagrid生成
 /// </summary>
 /// <param name="ctl"></param>
 public static void ToExcel(Control ctl)
 {
     HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
     HttpContext.Current.Response.Charset = "UTF-8";
     HttpContext.Current.Response.ContentEncoding = Encoding.Default;
     HttpContext.Current.Response.ContentType = "application/ms-excel";
     //image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword 
     ctl.Page.EnableViewState = false;
     var tw = new StringWriter();
     var hw = new HtmlTextWriter(tw);
     ctl.RenderControl(hw);
     HttpContext.Current.Response.Write(tw.ToString());
     HttpContext.Current.Response.End();
 }
 public static string GetHtmlControl(Control Control)
 {
     string output = "";
       if (Control == null) return output;
       using (StringWriter swControl = new StringWriter())
       {
     using (HtmlTextWriter htwControl = new HtmlTextWriter(swControl))
     {
       Control.RenderControl(htwControl);
     }
     output = swControl.ToString();
       }
       return output;
 }
Example #25
0
 /// <summary>
 /// Exports data supplied
 /// </summary>
 /// <param name="SourceData"></param>
 /// <param name="FileName"></param>
 /// <param name="PerfomNameMangle"></param>
 /// <returns></returns>
 public static void ExportToExcel(Control SourceData, string FileName, bool PerfomNameMangle)
 {
     try
     {
         HttpContext.Current.Session.Remove("exportReportData");
         System.IO.StringWriter stringWrite = new System.IO.StringWriter();
         System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
         SourceData.RenderControl(htmlWrite);
         HttpContext.Current.Session["exportReportData"] = stringWrite.ToString();
         HttpContext.Current.Response.Redirect("~/portal/shared/exportReport.aspx?f=" + GetExcelFileName(Path.GetFileNameWithoutExtension(FileName), PerfomNameMangle), false);
     }
     catch (Exception ex)
     {
     }
 }
Example #26
0
 public void ExportToExcel(Control ctr)
 {
     string s = @"<style> .text { mso-number-format:\@; } </script> ";
     base.Response.ClearContent();
     base.Response.Write("<meta   http-equiv=Content-Type   content=text/html;charset=utf-8>");
     base.Response.AddHeader("content-disposition", "attachment; filename=filename.xls");
     base.Response.ContentEncoding = Encoding.GetEncoding("GB2312");
     base.Response.ContentType = "application/excel";
     StringWriter writer = new StringWriter();
     HtmlTextWriter writer2 = new HtmlTextWriter(writer);
     ctr.RenderControl(writer2);
     base.Response.Write(s);
     base.Response.Write(writer.ToString());
     base.Response.End();
 }
Example #27
0
    public string RenderControl(Control ctrl)
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            StringWriter tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            ctrl.RenderControl(hw);
            return sb.ToString();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Example #28
0
 public static void DataControlToExcelAndDownload(Control ctl, string FileName)
 {
     if (string.IsNullOrEmpty(FileName))
     {
         FileName = "Excel.xls";
     }
     HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
     HttpContext.Current.Response.Charset = "UTF-8";
     HttpContext.Current.Response.ContentEncoding = Encoding.Default;
     HttpContext.Current.Response.ContentType = "application/ms-excel";
     ctl.Page.EnableViewState = false;
     StringWriter writer = new StringWriter();
     HtmlTextWriter writer2 = new HtmlTextWriter(writer);
     ctl.RenderControl(writer2);
     HttpContext.Current.Response.Write(writer.ToString());
     HttpContext.Current.Response.End();
 }
    private void Page_Load(object sender, System.EventArgs e)
    {
      bool bAccessAllowed = false;
      PortalDefinition.Module SelModule = GetModule(Request["Tab"], Request["Ctrl"]);
      if((SelModule != null) && (SelModule.type == "Newsticker"))     
      {
        string szUrl = Server.UrlDecode(Request["Src"]);
        if(UrlExist(Request["Tab"], SelModule, szUrl))
        {
          bAccessAllowed = true;

          // Ermitteln der Anzahl Einträge.
          int nNofItems = 0;
          try
          {
            nNofItems = Convert.ToInt32(Request["Nof"]);
          }
          catch(Exception)
          {
            nNofItems = 5;
          }

          // Wir Laden den gesuchten Feed.
          RssFeedItem Feed = new RssFeedItem(Request["Name"], szUrl, nNofItems, false);

          // Wir ermitteln die Repräsentation dieses Objekts.
          Control FeedParent = new Control();
          Feed.AddFeedRepresentation(FeedParent.Controls);

          // Wir geben die Repräsentation in HTML Code zurück.
          StringWriter StrWriter = new StringWriter();
          HtmlTextWriter TxtWriter = new HtmlTextWriter(StrWriter);
          FeedParent.RenderControl(TxtWriter);
          Response.Write(StrWriter.ToString());
        }
      }

      if(!bAccessAllowed)
      {
        Response.Write("No Access");
      }       

      Response.End(); 
    }
Example #30
0
    public static void GridOutExcel(Control gvTable, Page page, string Outname)
    {
        try
        {
            page.Response.ClearContent();
            //page.Response.Charset = "GB2312";
            page.Response.ContentEncoding = System.Text.Encoding.Default;
            page.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(Outname, System.Text.Encoding.UTF8) + ".xls");
            page.Response.ContentType = "application/excel";
            StringWriter o_sw = new StringWriter();
            HtmlTextWriter o_htw = new HtmlTextWriter(o_sw);
            gvTable.RenderControl(o_htw);
            page.Response.Write(o_sw.ToString());
            page.Response.End();

        }
        catch (Exception ex)
        { }
    }