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

FindControl on WebUserControl

2 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle Jones
Top achievements
Rank 1
Kyle Jones asked on 02 Sep 2009, 02:01 PM
Hey,

I am in a big hurry by my boss.  I need a way to find a control that is on a webusercontrol via javascript.  I have tried document.getelementbyid and $find('<% RadControl.ClientId %>') and nothing is working properly.  If anyone can get back to me really quick I would greatly appreciate it.

Kyle

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 02 Sep 2009, 04:24 PM
Hello Kyle Jones,

I suggest you try findControl/findElement methods

findControl
$telerik.findControl(parentElement, ControlID); 

example:
var radGrid = $telerik.findControl(document"RadGrid1"); 

or findElement
$telerik.findElement(parentElement, ElementID); 

example:
var myCheckBox = $telerik.findElement(document"CheckBox1"); 

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Charlie Crawford
Top achievements
Rank 1
answered on 04 Sep 2009, 02:13 AM
if you need quick and dirty, you might try running the application and then viewing source when your user control is loaded. Inside the source file, you need to search for whatever id value you gave the control, for example, if you have a text box with an id="txtName", search the source for "txtName" and you should find a very long control ID value with "txtName at the end. It usually is something like:  'NameOfContainerPage_NameOfContainerControl_NameOfControl'. Sometimes the id value contains '$' or other symbol, but it is almost always the names of the parent containers separated with an underscore '_', followed by the name of the control.

Once you have this value, you simply need to have a javascript line like:


 
var txtName = document.getElementById("HostingPageName_UserControlName_txtName");  
 
 
Be sure to test to see if the object was found or not:

 
if (txtName) {  
   
  //Perform some action with 'txtName':  
 
}  
 

Hope this helps,

Charlie
Tags
Grid
Asked by
Kyle Jones
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Charlie Crawford
Top achievements
Rank 1
Share this question
or