Render Grid

2 posts, 0 answers
  1. lampy
    lampy avatar
    47 posts
    Member since:
    Oct 2006

    Posted 03 Jun 2008 Link to this post

    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.

    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();  
  2. Rosen
    Admin
    Rosen avatar
    3235 posts

    Posted 06 Jun 2008 Link to this post

    Hi lampy,

    Unfortunately such scenario is not supported. The RadGrid control needs a real page with it's lifecycle.

    Let us know if further questions arise.

    Best wishes,
    Rosen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top