This is a migrated thread and some comments may be shown as answers.

Accessing Treeview from iframe

3 Answers 192 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 2
Markus asked on 13 Feb 2008, 02:17 PM
Hello everybody!
I know my question is not that telerik related, but probably you guys already needed something like this:
I have a mainpage with a radtreeview and an iframe. By clicking on a treenode, I load a new aspx page into the iframe. Now I want to access the radtreeview from the iframe, in order to update the tree.

Does anybody know any possibilities to access controls from "parent"frames ?

thx in advance & kind regards

3 Answers, 1 is accepted

Sort by
0
Jason Maronge
Top achievements
Rank 1
answered on 13 Feb 2008, 04:02 PM

On the iframe page you can use the "parent" property to access to javascript methods on the parent page.  So what I do is on  my frame page:

parent.RegisterDataChanged(window.name);

The RegisterDataChanged method on the parent page, where the treeview is, will insert an edit icon next to my text on the tree. You can do what ever you want to with the treeview on the main page in that method.  You can also have the main page call methods on the iframe page.

Main Page:

            window.GetFrameRef = function(frame)  
            {  
                var frameRef;   
 
                if(Prototype.Browser.IE)  
                {   
                    frameRef = document.frames(frame);  
                }  
                else if(Prototype.Browser.Gecko)  
                {   
                    frameRef = window.frames[frame];  
                }  
                  
                return frameRef;  
            }  
 
            window.GetFrameRef("<%=this.frameLocationHx.ClientID%>").UpdateIFramePage();  
 
 
 

This allows me to tell the iframe page to do an ajax call to update its contents. 

Hope this helps, 

Jason

0
Markus
Top achievements
Rank 2
answered on 14 Feb 2008, 07:31 AM
Hi Mason!

Thx for the promising answer. I think I have to resharpen my question. I would like to access the treeview in the "parentpage" from the codebehind class of the iframe.

Control parent = this.parent;
results in parent = null

I guess you meant to call parent.Javascriptmethod() from the aspx page.
Adding a onclientclick event to the button is a problem b/c I have to react on whether the function call from the code behind class was successful or not.

Is there a possibility to call a javascript method from the codebehind class? If so, I guess the javascript method can only be called after the method call in the codebehind class has finsihed?!
 Thx in advance & kind regards,
Markus

edit: I am able to call javascript code by now from the codebehind so that it fits to my needs. Nevertheless I have a problem manipulating the treeview with javascript. Manipulating the resulting DOM Model is a kind of hack to me. For example if i update the library, I cannot ensure that my javascript code adds nodes in the same way the radtreeview lib does when making a serversidecallback
0
Markus
Top achievements
Rank 2
answered on 14 Feb 2008, 10:19 AM
Hello everybody!

Finally I found the really powerful clientside Api of the telerik controls - they make life a lot easier :)
I simply call a javascript method:

ClientScript.RegisterClientScriptBlock(typeof(Page), "refresh", "<script type=\"text/javascript\">Refresh()</script>");

and in the method I call the parentwindow script:

function Refresh()
    {    
      nodeId = param('nodeId');
      parent.RefreshTree(nodeId);
    }


which finally ends up in that method:

        function RefreshTree(nodeId2Refresh)
        {
            var treeView = $find("<%= Tree.ClientID%>");
            var node = treeView.findNodeByValue(nodeId2Refresh);

            treeView.trackChanges();
            node.get_nodes().clear();
            node.set_expanded(false);
            treeView.commitChanges();
                node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.ServerSideCallBack);
            node.expand();
        }

Thx 4 help n' advice!
regards,
 markus
Tags
General Discussions
Asked by
Markus
Top achievements
Rank 2
Answers by
Jason Maronge
Top achievements
Rank 1
Markus
Top achievements
Rank 2
Share this question
or