Reputation: 18257
I have an HttpHandler in which I want to render the HTML for some custom controls.
Currently my code looks like this:
Page p = new Page();
var customControl = new CustomControl { Data = data, Blah = blah };
p.Controls.Add(customControl );
context.Response.Write(customControl.RenderToString());
The problem is that customControl (and child controls thereof) needs to do stuff in the OnInit, OnLoad and OnPreRender methods.
I have tried manually calling this methods through helper methods but I get various errors. My general problem is that I need the ASP.NET page lifecycle to run on the p
variable. Is there any way to get that to work?
Upvotes: 2
Views: 448
Reputation: 1003
i haven't come to try this yet...
works for me!
based on ScottGu's work, jim suggests something like this:
HttpContext.Current.Server.Execute(myPage, myTextWriter, false);
Upvotes: 1
Reputation: 88092
Sure. Instead of an HttpHandler use a regular page...
Barring that, change your control to work a bit differently.
Upvotes: 0