views:

199

answers:

1

Hi,

I have a set of code (noted below) in ProcessRequest(HttpContext context) in a generic handler .ashx file.

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

Now as I am in a HttpHander, I want to get the HTML of holder control and write it through context.Respose.Write().

Please help me through this.
Thanks in advance

Munim

+1  A: 

I have figured out the way by myself.

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