This is a migrated thread and some comments may be shown as answers.

[Solved] Can't Get Reference To Client-Side Control

1 Answer 20 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy
Top achievements
Rank 1
Andy asked on 29 Jan 2012, 05:36 PM
I'm using the ComboBox control, and I can't figure out how to get a reference to it in javascript. It functions correctly, just can't get a reference to it, client-side.

I declare it like this:

@(Html.Telerik().ComboBox()
                  .Name("SourceSiteSelector")
                    .AutoFill(true)
                    .DataBinding(binding => binding.Ajax().Select("_AjaxSourceSiteLoading", "Common"))
                    .Filterable(filtering => { filtering.FilterMode(AutoCompleteFilterMode.Contains); })
                        .ClientEvents(events => events.OnChange("SourceSiteSelector_onChange"))
                    .HighlightFirstMatch(true)
                    .HtmlAttributes(new { style = "width: 400px;" })
                )

But when I try to get a reference to it using the technique from the help files, this alert returns a value of true. It always returns null:
<script type="text/javascript">
    function SourceSiteSelector_onChange() {
        var combo = $('#SourceSiteSelector').data('tSourceSiteSelector');
        alert(combo == null);
    }
  
</script>

What am I missing?


Thanks!

Andy

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Jan 2012, 12:21 PM
Hello Andy,

The client-side objects for the Telerik Extensions can be obtained from the jQuery data by using a name in the format "t" + "ExtensionName". For example, to get the object for the ComboBox in your case, you should use the code in the snippet below:
var combo = $('#SourceSiteSelector').data('tComboBox');


Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or