Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > Can't Get Reference To Client-Side Control

Not answered Can't Get Reference To Client-Side Control

Feed from this thread
  • Andy avatar

    Posted on Jan 29, 2012 (permalink)

    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

    Reply

  • Daniel Daniel admin's avatar

    Posted on Jan 30, 2012 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > Can't Get Reference To Client-Side Control