本文整理汇总了C#中System.Web.UI.Page.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# Page.RenderControl方法的具体用法?C# Page.RenderControl怎么用?C# Page.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.Page
的用法示例。
在下文中一共展示了Page.RenderControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintWebControl
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
示例2: PrintWebControl
public void PrintWebControl(Control ControlToPrint)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ControlToPrint is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage);
((WebControl)ControlToPrint).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ControlToPrint);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
string wstawka = Server.MapPath("~").ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlToImage(strHTML, zmianaAdresu(wstawka)));
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
Response.Redirect("~/ListaImprez.aspx");
}
示例3: PrintWebControl
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
pg.StyleSheetTheme = "../CSS/order.css";
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlLink link = new HtmlLink();
link.Href = "../CSS/order.css";
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write("<head runat='server'> <title>Printer - Bản in tại Support.evnit.evn.com.vn</title> <link type='text/css' rel='stylesheet' href='../CSS/order.css'><link type='text/css' rel='stylesheet' href='../CSS/style.css'></head>");
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
示例4: GetFile
public void GetFile(Page page)
{
Button1.Visible = false;
HtmlDocument doc = new HtmlDocument();
var tw = new StringWriter();
var hw = new HtmlTextWriter(tw);
page.RenderControl(hw);
doc.LoadHtml(tw.ToString());
string path = Server.MapPath("ExportTemplate.txt");
string strtemplate = File.ReadAllText(path, Encoding.Default);
string result = strtemplate.Replace("@", doc.DocumentNode.SelectSingleNode("//div[@class='maincontant']").InnerHtml);
var str = "Export_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".doc";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("gb2312"); //注意编码
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(str, Encoding.UTF8));
HttpContext.Current.Response.ContentType = "application/application/ms-word";
HttpContext.Current.Response.Write(result);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
示例5: imgBtnExportarExcelEjecucion_Click
protected void imgBtnExportarExcelEjecucion_Click(object sender, ImageClickEventArgs e)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
gvIncidenciasBatch.AllowPaging = false;
gvIncidenciasBatch.DataBind();
gvIncidenciasBatch.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(gvIncidenciasBatch);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=ReporteIncidenciasBatch" + DateTime.Now.ToShortDateString() + ".xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
示例6: Render
/// <summary>
/// 用指定的用户控件以及视图数据呈现结果,最后返回生成的HTML代码。
/// 用户控件应从MyUserControlView<T>继承
/// </summary>
/// <param name="ucVirtualPath">用户控件的虚拟路径</param>
/// <param name="model">视图数据</param>
/// <returns>生成的HTML代码</returns>
public static string Render(string ucVirtualPath, object model)
{
if (string.IsNullOrEmpty(ucVirtualPath))
throw new ArgumentNullException("ucVirtualPath");
Page page = new Page();
Control ctl = page.LoadControl(ucVirtualPath);
if (ctl == null)
throw new InvalidOperationException(
string.Format("指定的用户控件 {0} 没有找到。", ucVirtualPath));
if (model != null)
{
MyBaseUserControl myctl = ctl as MyBaseUserControl;
if (myctl != null)
myctl.SetModel(model);
}
// 将用户控件放在Page容器中。
page.Controls.Add(ctl);
StringWriter output = new StringWriter();
HtmlTextWriter write = new HtmlTextWriter(output, string.Empty);
page.RenderControl(write);
// 用下面的方法也可以的。
//HttpContext.Current.Server.Execute(page, output, false);
return output.ToString();
}
示例7: imgBtnExportarExcelArchivos_Click
protected void imgBtnExportarExcelArchivos_Click(object sender, ImageClickEventArgs e)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
gvJobCancelacioneXTicket.AllowPaging = false;
gvJobCancelacioneXTicket.DataBind();
gvJobCancelacioneXTicket.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(gvJobCancelacioneXTicket);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=ArchivosDeProcedimiento.xls");
Response.Charset = "UTF-8";
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
示例8: PrintWebControl
public static void PrintWebControl(Control ControlToPrint, Control MyStyle)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ControlToPrint is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage);
((WebControl)ControlToPrint).Width = w;
}
System.Web.UI.Page pg = new System.Web.UI.Page();
pg.EnableEventValidation = false;
HtmlForm frm = new HtmlForm();
frm.Controls.Add(MyStyle);
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ControlToPrint);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
示例9: Export
protected bool Export()
{
try
{
//Descargo el objeto tabla de la sesion con nombre "p_c" ó (Plan Operativo)
HtmlTable objTable = (HtmlTable)Session["p_c"];
//Instancio un objeto del tipo StringBuilder objsb
StringBuilder objsb = new StringBuilder();
//Instancio un objeto del tipo System.IO.StringWriter sw
System.IO.StringWriter sw = new System.IO.StringWriter(objsb);
//Instancio un objeto del tipo HtmlTextWriter htw
HtmlTextWriter htw = new HtmlTextWriter(sw);
//Instancio un objeto del tipo System.Web.UI.Page
System.Web.UI.Page pagina = new System.Web.UI.Page();
//Instancio un objeto del tipo HtmlForm
var form = new HtmlForm();
//Asigno valores a propiedades del objeto page instanciado
pagina.EnableEventValidation = false;
pagina.DesignerInitialize();
//Agrego el formulario instaciado a la coleccionde paginas
pagina.Controls.Add(form);
//Agrego el objeto tabla a la coleccion de controles del formulario instanciado anteriormente
form.Controls.Add(objTable);
//Realizo el proceso de renderizacion para los elementos agregados a la pagina instanciada
pagina.RenderControl(htw);
//Limpio el canal de respuesta para esta peticion
Response.Clear();
//Habilito el buffer
Response.Buffer = true;
//Asigno el tipo de contenido
Response.ContentType = "application/vnd.ms-excel";
//Asigno el nombre del documento a exportar en el header del response
Response.AddHeader("Content-Disposition", "attachment;filename=Plan_Operativo.xls");
//Asigno el tipo de charset "UTF-8"
Response.Charset = "UTF-8";
//Establesco la configuracion por defecto para la codificacion
Response.ContentEncoding = Encoding.Default;
//Realizo el proceso de escritura para el objeto objsb
Response.Write(objsb.ToString());
//Finalizo la respuesta
Response.End();
return true;
}
catch (Exception) { return false; }
}
示例10: ProcessTemplate
public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response,
Domain domain)
{
if (!string.IsNullOrEmpty(templateName))
{
Page page = new Page();
page.Controls.Add(LoadControl(templateName, page, response, domain));
page.RenderControl(new HtmlTextWriter(writer));
}
}
示例11: imgBtnExcel_Click
protected void imgBtnExcel_Click(object sender, ImageClickEventArgs e)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
gdUsuario.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(gdUsuario);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=datosHotel.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
//Response.Clear();
//Response.AddHeader("content-disposition", "attachment;filename=Catalogo_Productos.xls");
//Response.Charset = "";
//Response.ContentType = "application/vnd.xls";
//StringWriter StringWriter = new System.IO.StringWriter();
//HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
//gvDatosAdmin.AllowPaging = false;
//Response.Write(StringWriter.ToString());
//Response.End();
}
示例12: PrintWebControl
public void PrintWebControl(Control ControlToPrint)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ControlToPrint is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage);
((WebControl)ControlToPrint).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ControlToPrint);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
string wstawka = Server.MapPath("~").ToString();
string path = String.Format("{0}\\Images\\Rezerwacje\\{1}.gif", Server.MapPath("~"), Session["ZamowienieId"]);
//korzystanie z biblioteki websiteScreenshote
WebsitesScreenshot.WebsitesScreenshot _Obj = new WebsitesScreenshot.WebsitesScreenshot();
WebsitesScreenshot.WebsitesScreenshot.Result _Result = _Obj.CaptureHTML(htmlToImage(strHTML, zmianaAdresu(wstawka)));
if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
{
_Obj.ImageFormat = WebsitesScreenshot.WebsitesScreenshot.ImageFormats.GIF;
_Obj.SaveImage(path);
}
_Obj.Dispose();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
Session[Cart.Ident] = null;
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
Response.Redirect("~/ListaImprez.aspx");
}
示例13: btnExportar_Command
protected void btnExportar_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Exportar")
{
if (GridView1.Rows.Count > 0 && GridView1.Visible == true )
{
//try
//{
lblMsj.Text = "";
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
System.Web.UI.Page page = new System.Web.UI.Page();
HtmlForm form = new HtmlForm();
GridView1.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Evaluaciones.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
//}
//catch (Exception ex)
//{
// EventLogger ev = new EventLogger();
// ev.Save("EvaluacionesDetalle, export excel ", ex);
//}
}
else
{
lblMsj.Text = "la tabla no contiene datos para exportar...";
}
}
}
示例14: Export
protected bool Export()
{
try
{
string html = txtgantt_html.Value;
html = html.Replace("!1!", ">");
html = html.Replace("!2!", "<");
html = html.Replace("!3!", "=");
html = html.Replace("!4!", "#");
html = html.Replace("!5!", "&");
HtmlGenericControl objTable = new HtmlGenericControl("table");
objTable.InnerHtml = html;
StringBuilder objsb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(objsb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
System.Web.UI.Page pagina = new System.Web.UI.Page();
var form = new HtmlForm();
pagina.EnableEventValidation = false;
pagina.DesignerInitialize();
pagina.Controls.Add(form);
form.Controls.Add(objTable);
pagina.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Cronograma.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(objsb.ToString());
Response.End();
return true;
}
catch (Exception) { return false; }
}
示例15: ExportToExcel
private void ExportToExcel(string nameReport, GridView wControl)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
ListarAsistencia form = new ListarAsistencia();
wControl.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(wControl);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}