This question is locked. New answers and comments are not allowed.
hello,
I'm trying to bind data to a ComboBox on the client-side.
This is a simple version of my jQuery handler:
The last line is giving me an error, as combo.data('tComboBox') is null:
Cannot call method 'dataBind' of null
Can you please advise?
Thanks
Pete
I'm trying to bind data to a ComboBox on the client-side.
This is a simple version of my jQuery handler:
$(function () { var str = '[{"Text":"--New--","Value":"0"}]' var obj = jQuery.parseJSON(str); var combo = $('#ComboBox'); combo = combo.data('tComboBox'); combo.dataBind(obj); });The last line is giving me an error, as combo.data('tComboBox') is null:
Cannot call method 'dataBind' of null
Can you please advise?
Thanks
Pete
4 Answers, 1 is accepted
0
Accepted
Hello Pete,
function bindComboBox() {
}
</script>
Regards,
Atanas Korchev
the Telerik team
You are probably calling this code before the combobox is initialized. The ScriptRegistrar is hookup the document.ready event as well and initializes all UI components there. I suspect your code happens before that hence the combobox is not initialized yet. As a workaround you can use the OnDocumentReady method of the ScriptRegistrar:
<% Html.Telerik().ScriptRegistrar().OnDocumentReady("bindComboBox();"); %>
function bindComboBox() {
var str = '[{"Text":"--New--","Value":"0"}]' var obj = jQuery.parseJSON(str); var combo = $('#ComboBox'); combo = combo.data('tComboBox'); combo.dataBind(obj);</script>
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Pete
Top achievements
Rank 1
answered on 04 Oct 2010, 07:16 PM
That did the trick... thanks Atanas!
0
Ignacio
Top achievements
Rank 1
answered on 18 Jun 2012, 03:11 PM
Hello Atanas,
I have a similar problem with the comboboxes, but the problem is when a button is clicked and I try to access to the data contained on it.
Here is a snnipet of my code. It fails when I try to access to any property as the data is null.
I verified that the application execute the SetComboboxActions()....which means that the comboboxes are already initialized, isn't it?
Thanks for your help!
Ignacio.
I have a similar problem with the comboboxes, but the problem is when a button is clicked and I try to access to the data contained on it.
Here is a snnipet of my code. It fails when I try to access to any property as the data is null.
I verified that the application execute the SetComboboxActions()....which means that the comboboxes are already initialized, isn't it?
@Html.Telerik().ScriptRegistrar().OnDocumentReady("SetComboboxActions()") <script> function SetComboboxActions(){ $('#SaveBtnTypeEdit').click(function(){ var combobox = $('#EditGroupTypeSelect').data('tComboBox') //...REST OF THE CODE }); }Thanks for your help!
Ignacio.
0
Ignacio
Top achievements
Rank 1
answered on 18 Jun 2012, 03:11 PM
Sorry I forgot to mention that this problem only happens in IE, not in Chrome.
Cheers,
Ignacio.
Cheers,
Ignacio.