RenderUserControl by pasing parameters
public static string RenderUserControl(string path, NameValueCollection nvc)
{
Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
if (nvc != null && nvc.Count > 0)
{
Type viewControlType = viewControl.GetType();
foreach (string key in nvc.Keys)
{
PropertyInfo property = viewControlType.GetProperty(key);
property.SetValue(viewControl, nvc[key], null);
}
}
pageHolder.Controls.Add(viewControl);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, true);
return output.ToString();
}
{
Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
if (nvc != null && nvc.Count > 0)
{
Type viewControlType = viewControl.GetType();
foreach (string key in nvc.Keys)
{
PropertyInfo property = viewControlType.GetProperty(key);
property.SetValue(viewControl, nvc[key], null);
}
}
pageHolder.Controls.Add(viewControl);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, true);
return output.ToString();
}
Comments
Post a Comment