I have a couple of questions as it pertains to JavaScript and Telerik Ajax controls:
1 - How can I reference a control using a variable? For example, I'm using the following code to enable/disable a RadTextBox based on a checkbox:
<script type=
"text/javascript"
>
function
enableDisableControl(bEnable) {
var
control = $find(
"<%= txt_ticketnumber.ClientID %>"
);
if
(bEnable) {
control.enable();
}
if
(!bEnable) {
control.disable();
}
}
</script>
I would like to make this more modular by doing this:
<script type=
"text/javascript"
>
function
enableDisableControl(bEnable, controlID) {
var
control = $find(
"<%= controlID.ClientID %>"
);
if
(bEnable) {
control.enable();
}
if
(!bEnable) {
control.disable();
}
}
</script>
and then calling it from checkbox's onclick client event.
onclick="enableDisableControl(this.checked, 'txt_ticketnumber');"
It works with standard ASP controls, but when I attempt to do this with Telerik controls I receive a null reference.
2 - How can I access ASP Ajax controls from a imported JavaScript. For example, the 1st example listed above works fine if its in the ASPX file wrapped in a RadScriptBlock. But if I move it to its own file (named something.js) and import it with the following code, I can no longer access controls. Its seems "out of scope". I've also tried wrapping it in a RadScriptBlack with no success.
<
script
type
=
"text/javascript"
src
=
"Scripts/ControlNameLocator.js"
></
script
>