开发者

Can I render html from ASP.NET Page objects outside ASP.NET applications?

I'm not talking about hosting ASP.NET with the 'ApplicationHost' class. For example, if I create a Console application, create a valid HttpContext object and pass it to the ProcessRequest of a custom Page object, will it fill the HttpReponse html like if it was runn开发者_如何转开发ing inside ASP.NET?


I don't see why not.

Try the RenderControl() method to get the html from a page or Web control.

static public string GetHTML(Control myControl)
{
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter myWriter = new HtmlTextWriter(sw);
        myControl.RenderControl(myWriter);
        return sw.ToString();
}

I use this to render GridViews asynchronously.


If you're talking custom ASP.NET controls, then you can programmatically create them and get them to render to a string easily enough. If that's something you're interested in doing, then I've done it in the past and can dig the code out for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜