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

[Solved] Client OnLoad Event - jQuery.data() is missing the object

1 Answer 62 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.
Emmet Ahlstrom
Top achievements
Rank 1
Emmet Ahlstrom asked on 27 May 2010, 01:57 AM
Are the controls client objects suppose to be available during the "OnLoad" client event? From my tests they aren't available until after the load event has fired, making the event useless for many scenarios. 

Take the NumericTextBox for example. The documentation (http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-numerictextbox-client-api-and-events.html) states the object can be accessed via the jQuery data store: 

var numericTextBox = $("#MyElementId").data("tTextBox"); 

Using the above code is null during the OnLoad event. The problem seems to be the "load" event is triggered in the $t.textbox function before the object has been added to the elements .data() storage. 

Reading more into the documentation it states:

events.OnLoad(() => 
            {%> 
                function(e) { 
                    // "this" is the sender. In this event handler will be the numericTextBox. 
                } 
            <%}); 

However "this" is the div element that contains the TextBox not the numericTextBox object. Trying to access the object via data store once again fails (i.e. "$(this).data('tTextBox')" ) the data is still null.

To solve the problem I've moved the "load" trigger out of the $t.textbox function and into the $.fn.tTextBox function after the .data() store is loaded. Example:
$.fn.tTextBox = function (options) { 
 
        // ..... 
 
            if (!$(this).data('tTextBox')) { 
                $(this).data('tTextBox'new $t.textbox(this, options)); 
                $t.trigger(this'load'); 
            } 
        }); 
    }; 

Am I completely missing the way we are suppose to work with the client objects? If so please let me know.

1 Answer, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 27 May 2010, 08:30 AM
Hi Emmet Ahlstrom,

This is a known limitation. Until we address it I suggest you use setTimeout(handler, 0) when handling the OnLoad event:

function (e) {
      var me = this;
      setTimeout(function() {
           var numericTextBox = $(me).data('tTextBox');
      }, 0);
}


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.
Tags
General Discussions
Asked by
Emmet Ahlstrom
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or