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

client side find control in antoher user control

3 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 09 Mar 2011, 05:13 PM
Hello,

I am using the client object model. I have a page with 3 user controls. I have JavaScript in UserControl1 that needs a reference to  a TreeView control which resides in UserControl2. Can I do that?
 
Secondly, I have the option of removing the User Controls and just using the page (aspx) would that save me compilcations later?

Updated** Attempt2 works:
// attempt1: does not resolve at compile time
var tree = $find("<%= RadTreeViewCommands.ClientID %>");
// attempt2: radTreeViewCommandsClientID is a global variable we set on the server
var tree = $find(radTreeViewCommandsClientID);

3 Answers, 1 is accepted

Sort by
0
Marcel
Top achievements
Rank 1
answered on 09 Mar 2011, 05:36 PM
This works:
// radTreeViewCommandsClientID is a global variable we set on the server using the ClientID property
var tree = $find(radTreeViewCommandsClientID);


// in code behind

script.AppendLine(

"<script language='javascript'>"

);

 

 

 

 

 

// allows us to find this control in JavaScript

 

 

script.AppendLine(

 

"var radTreeViewCommandsClientID = '" + RadTreeViewCommands.ClientID + "'"

);

 

 

script.AppendLine(

 

"var radGridLocationsClientID = '" + RadGridLocations.ClientID + "'"

);

 

 

script.AppendLine(

 

"</script>"

);

 

 

 

 

 

Page.ClientScript.RegisterStartupScript(

 

this.GetType(), "RadGridPracticesClientScripts"

, script.ToString());

 

 

 


0
Marcel
Top achievements
Rank 1
answered on 18 Dec 2015, 07:38 PM

Here is the formatted code:

// radTreeViewCommandsClientID is a global variable we set on the server using the ClientID property
var tree = $find(radTreeViewCommandsClientID);
 
// in code behind
script.AppendLine("<script language='javascript'>");
 
// allows us to find this control in JavaScript
script.AppendLine("var radTreeViewCommandsClientID = '"+ RadTreeViewCommands.ClientID + "'");
script.AppendLine("var radGridLocationsClientID = '" + RadGridLocations.ClientID + "'");
script.AppendLine("</script>");
 
Page.ClientScript.RegisterStartupScript(this.GetType(), "RadGridPracticesClientScripts", script.ToString());

0
Konstantin Dikov
Telerik team
answered on 23 Dec 2015, 06:58 AM
Hello Macrel,

Although that the approach that you have found is working correctly, another option is the use the findControl method from the static library:
The $telerik.findControl(container, id) method could find a control from our suite by passing the container element, where the control is placed and its ID.

Hope this helps.


Best Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Marcel
Top achievements
Rank 1
Answers by
Marcel
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or