我在一个通用的处理程序.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()编写它。
请帮我解决这个问题。
提前感谢
Munim
发布于 2010-02-13 17:14:21
我自己想出了办法。
using (StringWriter stringWriter = new StringWriter())
{
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
holder.RenderControl(htmlTextWriter);
HttpContext.Response.Write(stringWriter.ToString());
htmlTextWriter.Close();
stringWriter.Close();
}https://stackoverflow.com/questions/2257016
复制相似问题