Reputation: 3279
I'm using VS2010, C# to develop my ASP.NET web app, I've created a page dynamically (using several server side and HTML controls on the page). Now I'm going to send my page via email, I should have its content as HTML, how can I have my page HTML? of course I have a DIV (runat=....) which contains the parts which should be sent, how can I get its HTML content? innerHTML
gives me not literal error, what are my options? I want to have the final rendered content of my DIV
thanks
Upvotes: 0
Views: 741
Reputation: 2695
You can render an webforms control in code using something like the following:
var control = new Control();
StringBuilder b = new StringBuilder();
HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(b));
control.RenderControl(writer);
return b.ToString();
NOTE: there is also another method to render the whole page which might be a bit easier than what has already been proposed:
var writer = new StringWriter();
HttpContext.Current.Server.Execute(url, writer);
string output = writer.GetStringBuilder().ToString();
Upvotes: 3
Reputation: 102753
You might want to try simply downloading the page as a string using WebClient.
var wc = new WebClient();
string url = Request.Url.AbsoluteUri; // for the current page, otherwise set the URL
string html = wc.DownloadString(url);
Not sure if you're aware, but HTML emails are a tricky subject (email clients are like very crappy browsers, you can only use basic markup and CSS). I'd recommend checking out HTML Email Boilerplate for some tips and best practices on this.
Upvotes: 1