Thursday, September 24, 2015

RadAjaxManager and ClientIdMode="Static"

You may encounter this error when using the RadAjaxManager with controls that have their ClientIdMode set to Static.  

ASP.NET applies a prefix to all control IDs.  You can remove this prefix by setting the ClientIdMode property of  a control to "Static".   This makes it a little easier to access a control in Javascript using the controls' ID. 

This works just fine unless...... you're using the control in a RadAjaxManager.   Look at this code generated by the RadAjaxManager. with the txtScan ClientIdMode="Static"
Notice  id="txtScan"; just as you would expect when the ClientIdMode is Static.  However the RadAjaxManager wraps the control in a RadAjaxPanel and the name has the prefix characters added. This causes the "Unable to get property" error shown at the start of this article. 


Here is the generated code using ClientIdMode="Auto".
The prefix is added to the id.

You'll need to use syntax like this in your JavaScript code
var theTxtScanInput = document.getElementById('<%=txtScan.ClientID%>');   You may need to wrap your <script> section within a <telerik:RadCodeBlock runat="server">.



Moral of the Story

Don't use ClientIdMode="Static" when you're using the RadAjaxManager!



Visit www.BlueCanyonSoftware.com if you need custom software for your business.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.