I am trying to render a user control into a string. The application is set up to enable user to use tokens and user controls are rendered where the tokens are found.
StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HtmlTextWriter writer = new HtmlTextWriter(sw); Control uc = LoadControl('~/includes/HomepageNews.ascx'); uc.RenderControl(writer); return sb.ToString();
That code renders the control but none of the events called in the Page_Load of the control are firing. There’s a Repeater in the control needs to fire.
I’ve been using the following code provided by Scott Guthrie in his blog for quite some time:
The
object dataparameter, enables dynamic loading of data into the user control, and can be used to inject more than one variable into the control via an array or somethin similar.This code will fire all the normal events in the control.
You can read more about it here
Regards Jesper Hauge