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();
}

Comments

Popular posts from this blog

How to Fix Secure Connection Failed Error in Mozilla Firefox

PortQry solve your connectivity issues