2010/01/14
-
ASP.NET MVC 에서 사용자 정의 컨트롤의 내용을 문자열로 받기ASP.NET 2010. 1. 14. 13:12
간혹 사용자 정의 컨트롤(.ascx) 파일에서 처리한 내용을 Page에 바로 출력하는 것이 아니라, 문자열로 받아야 할 경우가 있습니다. ASP.NET 웹 폼의 경우에는 Page.LoadControl() 과 Control.RenderControl() 메서드를 이용하여 아래와 같은 코드로 사용자 정의 컨트롤이 처리한 내용을 문자열로 받아올 수 있습니다. Control control = LoadControl("~/MailTemplate.ascx"); ((MailTemplate)control).DestinationName = "Whistle"; StringBuilder stringBuilder = new StringBuilder(); using (StringWriter sw = new StringWriter(..