我在ProcessRequest(HttpContext context)
的通用处理程序.ashx
文件中有一组代码(如下所示)。
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
时,我希望获得HTML
holder
控件,并通过context.Respose.Write()
写下来。
请帮我解决这个问题 提前致谢
穆奈姆
答案 0 :(得分:2)
我自己已经找到了方法。
using (StringWriter stringWriter = new StringWriter())
{
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
holder.RenderControl(htmlTextWriter);
HttpContext.Response.Write(stringWriter.ToString());
htmlTextWriter.Close();
stringWriter.Close();
}