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
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");
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: