0

With ASP controls, like Telerik Controls, you have the Serverside which is referenced and the markup sent to the client. I was trying to do something NEW with it.

I have an ajax call which would return a json object of a MODAL. This modal will contain a TreeView. From what I was looking up, is that if i were to do this it wouldnt actually have a backend to reference, as it is essentially pinging the server for some 1time use output.

I am trying to change that. Whawt my goal is to make the ajax ping to build the TV and then on each subsequent node expansion, return all the children of the clicked Node? Sound easy right? Well, Not from the way I am doing it.

My ajax requests were just going to return a string, which is parsed with jQuery into HTML, and then inserted into the modal. I was trying various things such as:

StringWriter writer = new StringWriter();
HtmlTextWriter tOut = new HtmlTextWriter(writer);
ddFieldFilter.RenderControl(tOut);
tvFields = new RadTreeView();
tvFields.NodeExpand += new RadTreeViewEventHandler(tvFields_NodeExpand);
tvFields.NodeClick += new RadTreeViewEventHandler(tvFields_NodeClick);
startTree();
tvFields.RenderControl(tOut);
ret += writer.ToString();

This isnt working in the way I wanted to, and it will crash. It wont let me do a toString on the TreeView to put the markup into a string.

Sidenote: The tree doesnt NEED to be preservced, but if you could take the tree and send it back to the server for an update and then return it that works too.

I was thinking that after the tree was printed, i would then, on each leaf, just do an ajax request for TreeViewNodes, or.... something similar.

Thoughts? Ideas? From what I was looking at, and my thought processes, You CANNOT have a DIV be the target of a webserver for updates. That is more like a frame sort of thing, which i COULD do.... put a frame IN a div, but Im trying to keep it all looking nice, without frames.

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • 1
    I sort of follow the question... Take a look at something similar to what you describe here: http://stackoverflow.com/a/7802527/345490 – Icarus Jul 18 '12 at 18:26
  • It works for me, and made me figure out some alternative options. Also, If you put it as an answer, Icarus, i will give you the answer. It was helpful and beneficial. – Fallenreaper Jul 19 '12 at 12:41
  • @Icarus , Is there a way to, instead of doing it clientside, make a ajax call to a webservice which would define a TreeView and then use RENDER or something to send the string to the client? – Fallenreaper Jul 19 '12 at 12:48
  • 1
    Yes, it's absolutely possible but that's a hell of hack, IMO. The answer I linked is more elegant, easier to maintain and very likely performs better. Here's a link that explains how to do what you ask, anyway: http://stackoverflow.com/questions/450431/dynamically-loading-a-usercontrol-with-loadcontrol-method-type-object. Good luck. – Icarus Jul 19 '12 at 14:31
  • 1
    BTW: be wary of the fact that the technique of loading the user control on a temporary page, to then just return the html string will cause you issues with postbacks due to invalid viewstate. The reason being that the rendered html string will contain another form element with another viewstate hidden element; therefore, when you post back, you'll end up submitting the viewstate from the control and not from the page. Make sure you remove the `form` and the `viewstate` elements from the rendered control before returning the string so it's never posted back. – Icarus Jul 19 '12 at 14:39
  • I thank you for your information and will take this into consideration. I am leaning to moreso just make my own tree which will look different, and then just design it as needed to do what I want. I feel the hack I would implement, while would be understandable to me, would not be for the person(s) in charge of understanding, styling, and documenting. – Fallenreaper Jul 19 '12 at 15:37

0 Answers0