Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering an aspx page in another one

In my web project's business object editor page, I'm sending a notification email to the administrator after an object insert or update. But instead of sending a plain text mail, i want to send the html output of another aspx page(Notification.aspx) i simply prepared for this purpose.

First i thought, I can create an instance of Notification.aspx then use it's RenderControl method for getting the output.

However, in the codebehind of Editor.aspx page, i can't even reach the Notification's reference to create a new instance.

I wonder what is the best practice for loading and rendering a page in another one...

Thanks.

like image 341
koraytaylan Avatar asked Mar 15 '09 13:03

koraytaylan


1 Answers

You can render a page by doing this:

StringWriter _writer = new StringWriter();
HttpContext.Current.Server.Execute("MyPage.aspx", _writer);

string html = _writer.ToString();
like image 118
MartinHN Avatar answered Nov 18 '22 11:11

MartinHN