C# 从HttpHandler呈现HtmlGenericControl
我在一个通用处理程序C# 从HttpHandler呈现HtmlGenericControl,c#,.net,asp.net,httphandler,C#,.net,Asp.net,Httphandler,我在一个通用处理程序.ashx文件中的ProcessRequest(HttpContext context)中有一组代码(如下所述) HtmlGenericControl holder = new HtmlGenericControl("div"); //Set holder's properties and customization HtmlGenericControl button1 = new HtmlGenericControl("input"); //Set button1's pr
.ashx
文件中的ProcessRequest(HttpContext context)
中有一组代码(如下所述)
HtmlGenericControl holder = new HtmlGenericControl("div");
//Set holder's properties and customization
HtmlGenericControl button1 = new HtmlGenericControl("input");
//Set button1's properties and customization
holder.Controls.Add(button1);
HtmlGenericControl button2 = new HtmlGenericControl("input");
//Set button2's properties and customization
holder.Controls.Add(button2);
HtmlGenericControl button2 = new HtmlGenericControl("input");
//Set button2's properties and customization
holder.Controls.Add(button2);
现在,由于我在一个HttpHander
,我想获得holder
控件的HTML
,并通过context.Respose.write()
编写它
请帮我解决这个问题。提前谢谢
穆尼姆我自己找到了路
using (StringWriter stringWriter = new StringWriter())
{
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
holder.RenderControl(htmlTextWriter);
HttpContext.Response.Write(stringWriter.ToString());
htmlTextWriter.Close();
stringWriter.Close();
}