Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [WebMethod]
- public static string LoadAlternates(string productId, string pnlId)
- {
- object[] parameters = new object[] { pnlId, productId };
- return ControlAsString(typeof(PopupControl), parameters);
- }
- private static string ControlAsString(Type controlType, object[] parameters)
- {
- Page page = new Page();
- UserControl controlToLoad;
- /*
- *calling load control with the type results in the
- *stringwriter returning an empty string
- */
- controlToLoad = page.LoadControl(controlType, parameters) as UserControl;
- /*
- *However, calling LoadControl with the following overload
- *gives the correct result, ie the string rep. of the control.
- */
- controlToLoad = page.LoadControl(@"~/RepeaterSamples/PopupControl.ascx") as UserControl;
- //some more code, then this...
- page.Controls.Add(controlToLoad);
- StringWriter sw = new StringWriter();
- HttpContext.Current.Server.Execute(page, sw, false);
- return sw.ToString();
- }
Add Comment
Please, Sign In to add comment