1
는 현재 내가 ( 뒤에 어떤 코드 ) 단일 Example.aspx 파일을 가지고 있고, 그것은이 컨트롤을 채우는,로드 그것의 OUPUT을 얻을 싶어 (A HTTP 처리기 내부에) 그것으로 무언가를 .ASPX 파일에서 동적으로 인스턴스화 된 페이지의 컨트롤을 채우시겠습니까?
// Gets the page and instantiates it?
Type type = BuildManager.GetCompiledType("~/Example.aspx");
Page page = (Page)Activator.CreateInstance(type);
// ProcessRequest of page here?
// Error happens here, the page doesn't have any controls (but there is a label).
((Label)page.FindControl("Label")).Text = "Hello World";
using (StringWriter output = new StringWriter())
{
// Execute the page and output the result into the string writer.
HttpContext.Current.Server.Execute(page, output, false);
// Do something with the output (or save it, email it, etc)
// ...in this case we render it.
context.Response.ContentType = "text/html";
context.Response.Write(output.ToString());
}
그러나 페이지 인스턴스가 모든 컨트롤이 없기 때문에 작동하지 않습니다 :
는 내가 뭐하는 거지 것은 이것이다 (이 자식 컨트롤을 만들 필요가 있습니까?).
내가 추가하는 경우 :
page.ProcessRequest(HttpContext.Current);
작동,하지만 난 그게 전체 페이지 수명주기를 실행 생각하고 그 응답으로 페이지를 렌더링 포함, 뭔가 내가 싶지 않아요.
왜이 작업을 수행 하시겠습니까? (나는 순수한 호기심에서 물어 봅니다.) 이것은 단지 실험입니까, 아니면 특별한 목적을 염두에두고 있습니까? – jwiscarson
http://stackoverflow.com/a/1732213/284240 –
@jwiscarson : 이것은 모두 간단한 실험을 위해 asp.net을 사용하려는 실험 및 시도입니다. 내 자신의 templating 시스템을 구현하는 대신 asp.net이 수행하기를 원합니다. –