Client side removeHandler error

5 posts, 1 answers
  1. JiriSchmitt
    JiriSchmitt avatar
    10 posts
    Member since:
    Apr 2007

    Posted 21 Jan 2011 Link to this post

    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
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 Jan 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JiriSchmitt
    JiriSchmitt avatar
    10 posts
    Member since:
    Apr 2007

    Posted 27 Jan 2011 Link to this post

    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

  5. JiriSchmitt
    JiriSchmitt avatar
    10 posts
    Member since:
    Apr 2007

    Posted 30 Jan 2011 Link to this post

    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.
  6. Answer
    Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 31 Jan 2011 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017