Tuesday, January 17, 2012

Check if control exists by ClientInstanceName

In order to check whether a specific Devexpress control exists using javascript, you can use the ASPxClientUtils.IsExists method. If the control exists, the method words as expected. The problem rises when the control you are looking for doesn't exist as this will cause the error 'ReferenceError: myControl is not defined' in javascript. In order to solve this, first use the eval function to check whether the object exists and put it inside a try catch.
var obj = null;
try { obj = eval('myClientASPxGridview'); } catch (e) { }
if (ASPxClientUtils.IsExists(obj))
    myClientASPxGridview.PerformCallback();
Link to ASPxClientUtils.IsExists documentation

No comments:

Post a Comment