1

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

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • Where in your page is this code being executed? – ScottieMc Jul 12 '12 at 16:46
  • What i was going to do is take the control and .toString() it to get the markup and then pass the markup to a client machine. Then on the client, reconstruct the client/server connection – Fallenreaper Jul 12 '12 at 16:48
  • it is executed in a webservice method, which builds it all serverside and then pushes the markup to the client. – Fallenreaper Jul 12 '12 at 16:49
  • 1
    I don't think what you're trying to do is supported. See [here](http://www.telerik.com/community/forums/aspnet-ajax/combobox/page-cannot-be-null-please-ensure-that-this-operation-is-being-performed-in-the-context-of-an-asp-net-request.aspx). – ScottieMc Jul 12 '12 at 16:59
  • Thanks for the information. I will find a different way to accomplish the tasks. If you put that as the answer, i will accept it.\ – Fallenreaper Jul 12 '12 at 17:06

1 Answers1

1

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

ScottieMc
  • 656
  • 9
  • 16