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

Client side removeHandler error

4 Answers 96 Views
Input
This is a migrated thread and some comments may be shown as answers.
JiriSchmitt
Top achievements
Rank 1
JiriSchmitt asked on 21 Jan 2011, 05:10 PM
Hello,

I have own composite control inherited from RadWebControl. It contains RadTextBox control where I need handle keyup client event.
I have implemented client class for it and I attached event in initialize function. In dispose function I'm removing this event handler but it causes javascript error:

Line: 6
Error: '_events' is null or not an object

Here is the script:

nData.KnowledgeManagement.Web.UI.Searcher.prototype =
{
    initialize: function () {
        nData.KnowledgeManagement.Web.UI.Searcher.callBaseMethod(this, 'initialize');
  
        // SearchTextBox
        this._searchTextBox = $find(this.get_id() + '_searchTextBox');
        this._keyUpDelegate = Function.createDelegate(this, this._keyUp);
        $addHandler(this._searchTextBox._textBoxElement, "keyup", this._keyUpDelegate);
  
        // XmlHttpPanel
        this._xmlHttpPanel = $find(this.get_id() + '_xmlHttpPanel');
        this._xmlHttpPanel._searcher = this;
        this._xmlHttpPanel.add_responseEnding(this._xmlHttpPanelResponseEnding);
        this._xmlHttpPanel.add_responseError(this._clientResponseError);
    },
  
    dispose: function () {
        nData.KnowledgeManagement.Web.UI.Searcher.callBaseMethod(this, 'dispose');
  
        if (this._keyUpDelegate) {
            $removeHandler(this._searchTextBox._textBoxElement, "keyup", this._keyUpDelegate);
            this._keyUpDelegate = null;
        }
  
        this._xmlHttpPanel.remove_responseEnding(this._xmlHttpPanelResponseEnding);
        this._xmlHttpPanel.remove_responseError(this._clientResponseError);
    },
  
    _keyUp: function () {
        this._search(this._searchTextBox._textBoxElement.value);
    },
    ...
}

Cound you tell me what I have wrong?
Thanks
Jiri

4 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 27 Jan 2011, 10:07 AM
Hello Jiri,

I would suggest you to revise the following online resources:
http://forums.asp.net/t/1315438.aspx
http://stackoverflow.com/questions/3893621/events-is-null-or-not-an-object-error-only-when-compilation-debug-false
http://www.tek-tips.com/viewthread.cfm?qid=940870

Also note that we do not support inheriting from base RadControl.

Kind regards,
Maria Ilieva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
JiriSchmitt
Top achievements
Rank 1
answered on 27 Jan 2011, 12:17 PM
Hello Maria,

thanks for reply. I found that problem is because dispose method on SearchTextBox (RadTextBox) control is called before dispose method on my parent control.
And RadInputControl finishing with "this._textBoxElement._events = null;" code, which causes error during call $removeHandler from my parent control.

So maybe there is better way how to register/unregister handler on RadTextBox control. I need hande keyup event.
Is there something for it? I tried add_keyPress but it is not fire for all changes in textbox.

I need something like:
this._searchTextBox.add_keyUp(this._keyUp);
  ...
this._searchTextBox.remove_keyUp(this._keyUp);

Thank you
Jiri

0
JiriSchmitt
Top achievements
Rank 1
answered on 30 Jan 2011, 06:17 PM
I got answer in my supprot ticket:
--------------------------------------

Regarding the issue with removing the handler, the $addHandler method accepts fourth Boolean argument, that shows whether the handler should be automatically removed when the element is disposed, so I would recommending passing true, and you would not need to remove it explicitly. This is the way I have done it in your project.
0
Accepted
Maria Ilieva
Telerik team
answered on 31 Jan 2011, 04:15 PM
Hello Jiri,

I'm glad that the solution provided by my colleague helps you fix the problem. Let us know if further assistance is need.


Best wishes,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Input
Asked by
JiriSchmitt
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
JiriSchmitt
Top achievements
Rank 1
Share this question
or