Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
525
CellExitedEditMode unsubscribe for memory leak
posted

Hi,

I have a Silverlight Usercontrol where right below the InitializeComponent(); line, I subscribe to grvLiveData.CellExitedEditMode += new EventHandler<CellExitedEditingEventArgs>(grvLiveData_CellExitedEditMode);

I would like to unsubscribe to this event when a user clicks a save button on a parent usercontrol.

When this save button is clicked, another usercontrol is loaded, but the first usercontrol (containing the gridview and CellExitedEditMode subsciption )remains on the master usercontrol.

The user then has the possibility to activate the first usercontrol yet again containing the gridview. Problem is that I can't subscribe to the CellExitedEditMode again on the Page_Loaded event because the CellExitedEditMode isn't triggered when I subscribe it on the page_loaded event.

And the line below the CellExitedMode line isn't called anymore because the usercontrol exists already on the viewport.

I would like to subscribe/unsubscribe to this event each time, because memory raises each time when I don't unsubscribe to it.

Any tips ?

Regards,

Nicolas

Parents
No Data
Reply
  • 21382
    Suggested Answer
    posted

    Hello Nicolas,

    I would probably add a method to the UserControl, something like AddRemoveEvent(bool attachEvent) which I would call when the Control is loaded and then subsequently called from your parent control when it is shifting user controls around and bringing them to the front.

     

    so the method would look something like

    public void AddRemoveEvent(bool add)

    {

    // remove event handler

    this.grid.Event -= EventHander;

    if (add)

      this.grid.Event += EventHandler

    }

Children
No Data