首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从HttpHandler渲染HtmlGenericControl

从HttpHandler渲染HtmlGenericControl
EN

Stack Overflow用户
提问于 2010-02-13 17:03:31
回答 1查看 1.9K关注 0票数 0

我在一个通用的处理程序.ashx文件中有一组ProcessRequest(HttpContext context)代码(如下所示)。

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-13 17:14:21

我自己想出了办法。

代码语言:javascript
复制
using (StringWriter stringWriter = new StringWriter())
{
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
    holder.RenderControl(htmlTextWriter);
    HttpContext.Response.Write(stringWriter.ToString());
    htmlTextWriter.Close();
    stringWriter.Close();
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2257016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档