Loading Dynamic User Control in Ext.net Desktop Module causes problem

  1. #1

    Loading Dynamic User Control in Ext.net Desktop Module causes problem

    I'm using ext.net Desktop and desktop Modules. Structure of my application is Like below ;
    Desktop -> Desktop Module ->Panel -> User Controls
    Which mean : I have Desktop with Multiple Module Inside it. each module have panel that I can load User controls inside it. user clicks a button and I load appropriate User Control inside it. each user control has a toolbar that do CRUD operation inside that user control. the problem is, when I add for example "Persons" user control to panel of module one, every thing works great. but when I remove this control and add this control for second time, the the "init" method of this control calls two times on direct method calls, means if i press load data of all Person, the Load method calls two times. and if I remove and re add this control for third times every methods calls three time.
    I load user controls whit "this.LoadControl()" method and add the result control to "Panel.ContentControls" and then call "Panel.UpdateControls()".
    In each postback that causes by DirectMethodes that invoke by pressing a button on toolbar inside a user control, I recreate this user control and add two Panel without calling "UpdateContent".
    thank you for your attention and help.
  2. #2
    It is hard to understand whats wrong using text description only
    Please post simple test sample reproduces the issue
  3. #3
    Quote Originally Posted by Vladimir View Post
    It is hard to understand whats wrong using text description only
    Please post simple test sample reproduces the issue
    I create simplified version of my solution , but I can't attach .rar file in this forum. then I uploaded it on 4shared.
    http://www.4shared.com/rar/iv5mp13D/ExtnetExample.html

    only note that when i remove user control and re add it, the problem raises.
    thank you for your effort.
    Last edited by ali; May 26, 2013 at 6:24 AM.
  4. #4
    Just post code directly in this thread, we don't need any archives
  5. #5
    Because I can't post part of code here for full understanding, i create sample project and posted a solution here.
    if it's possible for you, please download and check the whole sample project.

    Anther notation is that, I think I found the cause of problem but I can not find a solution for it. because i want to have only one toolbar, I created a Toolbar control whit multiple button and uses "Listeners.Click.BroadcastOnBus" for each of this button to publish related events.
    the solution works great if we do not remove the controls that publish an event, but when we remove this controls , their broadcasted events does not unpublish and hence when we re add this controls to page, this events raise multiple times.
    any hint for this problem?
  6. #6
    Thanks for your report, the fix will be available in the next release, at this moment you can use the following workaround (just include it to head tag of the page)

    Ext.net.Bus.unsubscribe = function (name, fn, scope) {
                var _events = this.events;
                this.events = this.directListeners;
                this.un("message", fn, scope || this);
                this.events = _events;
            };
    
    
            Ext.net.MessageBus.initEvents = function (owner) {                        
                if (owner.messageBusListeners) {                
                    var busListeners = [];
                    Ext.each(owner.messageBusListeners, function (listener) {
                        var bus = listener.bus ? Ext.net.ResourceMgr.getCmp(listener.bus) : Ext.net.Bus,
                            name = listener.name || "**";
    
    
                        if (owner instanceof Ext.net.MessageBus) {
                            bus = owner;
                        }
    
    
                        if (!bus) {
                            throw new Error("Bus is not found: " + listener.bus);
                        }
    
    
                        listener.scope = listener.scope || owner;
    
    
                        busListeners.push({name : name, fn : bus.subscribe(name, listener), bus: bus, scope: listener.scope});                    
                    });
    
    
                    if (owner.on && busListeners.length) {
                        owner.on("destroy", function () {
                            Ext.each(busListeners, function (item) {
                                item.bus.unsubscribe(item.name, item.fn);
                            });
                        });
                    }
    
    
                    owner.messageBusListeners = null;
                }
    
    
                if (owner.messageBusDirectEvents) {
                   var busDirectEvents = [];
                    Ext.each(owner.messageBusDirectEvents, function (listener) {
                        var bus = listener.bus ? Ext.net.ResourceMgr.getCmp(listener.bus) : Ext.net.Bus,
                            name = listener.name || "**";
    
    
                        if (owner instanceof Ext.net.MessageBus) {
                            bus = owner;
                        }
    
    
                        if (!bus) {
                            throw new Error("Bus is not found: " + listener.bus);
                        }
                        listener.isDirect = true;                    
                        listener.scope = listener.scope || owner;
                        busDirectEvents.push({name : name, fn : bus.subscribe(name, listener), bus: bus, scope: listener.scope});
                    });
    
    
                    if (owner.on && busDirectEvents.length) {
                        owner.on("destroy", function () {
                            Ext.each(busDirectEvents, function (item) {
                                item.bus.unsubscribe(item.name, item.fn, item.scope);
                            });
                        });
                    }
    
    
                    owner.messageBusDirectEvents = null;
                }
            };
  7. #7
    thanks for your attention

Similar Threads

  1. Replies: 1
    Last Post: Jan 28, 2013, 5:26 AM
  2. Render dynamic module in Desktop
    By AIM System Ltd in forum 2.x Help
    Replies: 0
    Last Post: Jul 25, 2012, 7:31 AM
  3. Dynamic User Control Loading
    By Rupesh in forum 1.x Help
    Replies: 0
    Last Post: Apr 08, 2011, 7:48 AM
  4. Replies: 8
    Last Post: Jan 25, 2011, 4:21 AM
  5. Replies: 5
    Last Post: Jan 19, 2011, 3:17 PM

Tags for this Thread

Posting Permissions