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

How to get rad control object in javascript from custom Sharepoint control

3 Answers 174 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Herb Ramos
Top achievements
Rank 1
Herb Ramos asked on 04 Nov 2007, 02:14 PM
Hi,

I'm creating a custom sharepoint control (ascx) contains has a RadTreeView control.  I am trying to get the tree control instance from a javascript
function as follows:

   // Gets a handle to the TreeView.
   function GetTreeControl()
   {
       // Get a handle to the TreeView.
       var tree =  document.getElementById('radTreeModule');
    //var tree =  document.getElementById('<%= radTreeModule.ClientID %>');
       if ( tree == null || tree == undefined )
           return null;
       return tree;
   }  

Note: i tried two options for getElemenetById.

I get null when using 
       var tree =  document.getElementById('radTreeModule');

The tree nodes don't behave properly when using
   var tree =  document.getElementById('<%= radTreeModule.ClientID %>');



I read somewhere that the INamingContainer implemented by Sharepoint may not support document.getElementById('<%= xxx.ClientID %>'); syntax.

So how do I get the tree object for this custom control in javascript within the custom control?






3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 06 Nov 2007, 08:25 AM
Hi Herb Ramos,

Thanks for writing to us and your question.

Actually, the proper way to obtain the treeview client-side instance is using the following syntax:

var tree = <%= radTreeModule.ClientID %>;
or
var tree = window["<%=
radTreeModule.ClientID  %>"];

Thus, you will get the client side object and a reference to all its properties and methods exposed at the client-side.

Hope this helps.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sean
Top achievements
Rank 1
answered on 25 Feb 2008, 05:57 PM
I've implemented this solution to great success, however the decision was made recently to move the entire in-page set of javascript functions to a .js file.  Of course, this has the unfortunate side-effect of the page being unable to process the <%= %> tag from within the .js file, and/or losing context for the control.

I would like to know if there's some way of referencing these controls through JavaScript if running from an included external file.

There are a few other solutions I can think of, such as leaving the functions for any affected controls on the page (somewhat defeating the purpose), or passing in the "window[]" code as parameters to those functions when the appropriate controls that fire them have their attributes set -- which, even assuming it works, unnecessarily duplicates code, makes things harder to debug, and just seems like an all-around anti-pattern. 

(As for why precisely I have to make this work from a .js file, let's just take it as read that I do.)

~Sean
0
Nikolay
Telerik team
answered on 26 Feb 2008, 09:30 AM
Hello Sean,

I believe that the only way would be using window["RadTreeView1"], where RadTreeView1 is the exact client id of the tree.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Sharepoint Integration
Asked by
Herb Ramos
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Sean
Top achievements
Rank 1
Share this question
or