【问题标题】:Render HtmlGenericControl from a HttpHandler从 HttpHandler 渲染 HtmlGenericControl
【发布时间】:2010-02-13 09:03:31
【问题描述】:

我在通用处理程序.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 中,我想获得holderHTML 控件并通过context.Respose.Write() 编写它。

请帮我解决这个问题。
提前致谢

穆尼姆

【问题讨论】:

    标签: c# .net asp.net httphandler


    【解决方案1】:

    我自己想办法了。

    using (StringWriter stringWriter = new StringWriter())
    {
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        holder.RenderControl(htmlTextWriter);
        HttpContext.Response.Write(stringWriter.ToString());
        htmlTextWriter.Close();
        stringWriter.Close();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 2014-12-04
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多