问题
I am new to radcontrols. I want to know how to get type of control of a radcontrol using javascript. For normal asp.net controls we write:
var controlType=document.getElementById("hdnCode").type;
The above code will give type of control as "hidden", and for textbox it will give "text".
When i try to get type of a rad control it gives undefined as shown here:
var controlType=document.getElementById("RadComboBox1").type;
The above code gives undefined.
Please suggest me how to get type in case of Rad Controls.
Thanks
回答1:
You can't really check for the type of the control like this, these are complex objects (IScriptControls) and not simple HTML elements.
You can try the following approach to see the instances of given type (the if block shows how you can make a check only):
function get_allRadCombos()
{
var allRadCombos = [];
var allRadControls = $telerik.radControls;
// all RadControls are referenced
for (var i = 0; i < allRadControls.length; i++)
{
var element = allRadControls[i];
if (Telerik.Web.UI.RadComboBox && Telerik.Web.UI.RadComboBox.isInstanceOfType(element))
{
allRadCombos.push(element);
}
}
// only the RadCombos are gathered into an array
return allRadCombos;
}
The $telerik.radControls is an array the RadControls create and populate, you can check a given instance by referencing it through the $find(controlClientID) method
来源:https://stackoverflow.com/questions/16212730/unable-to-get-type-of-control-for-radcombobox-in-javascript