For an E-Commerce system, after the order is placed I have a custom user control that displays the order details. I also want to write the same order details to an email so I want to write the contents of the user control out to a string that I can add to the body of the email.
I tried using RenderControl but, the none of the dynamically populated label controls on the user control were populated.
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
OrderDetails1.RenderControl(htw);
return sb.ToString();
I found somewhere else that I could add the control to a page and then write the output of the page to a string but this felt kludgy.
It seems like I should be able to capture the contents of the control when it is first rendered so that I don’t have to repopulate it and re-render it. Anyone know how?
If not, what’s the cleanest way to populate the control?
Turns out the
RenderControlcode was proper, I just needed to call the controls FillData() function to repopulate the controls from the database.