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();
}