I am working on a TreeView and have to execute the renderControl() method. When it fires, it gives an exception: InvalidOperationException: Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.
I have the following code when will comment where the error is:
try{
StringWriter writer = new StringWriter();
HtmlTextWriter tOut = new HtmlTextWriter(writer);
ddFieldFilter.RenderControl(tOut); //This doesnt error.
tvFields = new RadTreeView();
tvFields.NodeExpand += new RadTreeViewEventHandler(tvFields_NodeExpand);
tvFields.NodeClick += new RadTreeViewEventHandler(tvFields_NodeClick);
startTree();
tvFields.RenderControl(tOut); //Errors here.
String context = writer.toString();
}catch(Exception e){
throw new Exception("Error Loading Page: " + e.Message);
}
Do you think it might be because there is currently content in the writer? I was thinking to clear or flush it to the string and then rebuild it. I wasnt sure it would append onto the current buffer
Let me know if you need additional Information
What you're trying to do doesn't look like it is currently supported. Although this question is in regards to the Asp.NET ColorPicker
control, I believe it applies to the RadTreeView
control as well.
Via the Telerik Support Center:
Q: Is there any way to get the ColorPicker to render without a page? I had to add it in a situation where I write directly in the aspx, not aspx.cs. Also, I might need to do it from a generic handler, ashx. Is this possible?
A: The control needs to be added to a page, either in its markup, or in its code-behind. You could try the RenderControl method and write to Response.OutputStream, yet this is not a supported scenario and it success cannot be guaranteed, so I advise against such attempts.
Regards,
Marin
the Telerik team