Hello,
Is it possible to render a usercontrol containing an ASP.Net AJAX RadGrid via to string? I have tried and failed and wanted to see if anyone has gotten it to work. The code that I use to render is below.
Is it possible to render a usercontrol containing an ASP.Net AJAX RadGrid via to string? I have tried and failed and wanted to see if anyone has gotten it to work. The code that I use to render is below.
public static string RenderView(string path, object data) |
{ |
Page pageHolder = new Page(); |
UserControl viewControl = (UserControl)pageHolder.LoadControl(path); |
if (data != null) |
{ |
Type viewControlType = viewControl.GetType(); |
PropertyInfo propertyInfo = viewControlType.GetProperty("DetailsDataSource"); |
if (propertyInfo != null) |
{ |
propertyInfo.SetValue(viewControl, data, null); |
} |
else |
{ |
throw new Exception("View file: " + path + " does not have a public Data property"); |
} |
} |
pageHolder.Controls.Add(viewControl); |
StringWriter output = new StringWriter(); |
HttpContext.Current.Server.Execute(pageHolder, output, false); |
return output.ToString(); |
} |