[0.82] IsAjaxRequest and creating tabs and GridPanels in code behind problem

  1. #1

    [0.82] IsAjaxRequest and creating tabs and GridPanels in code behind problem

    Hi

    so i am creating tab and gridpanel in code behind at PageLoad()

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Ext.IsAjaxRequest)
            {
                CreateDeptTab(dept);
            }     
            
        }
    
        private void CreateDeptTab(Department dept)
        {
            string deptName = MakeDeptName(dept.Name);
    
            Store DepartmentPeopleStore = new Store();
            DepartmentPeopleStore.ID = deptName + "PeopleStore";
            DepartmentPeopleStore.AutoLoad = true;
            DepartmentPeopleStore.SerializationMode = SerializationMode.Complex;
            JsonReader deptPeopleReader = new JsonReader();
            deptPeopleReader.ReaderID = "Id";
            deptPeopleReader.Fields.Add("Name");             
            DepartmentPeopleStore.Reader.Add(deptPeopleReader);
    
            FitLayout DeptFitLayout = new FitLayout();
            GridPanel DeptPeopleGrid = new GridPanel();
            DeptPeopleGrid.ID = deptName + "PeopleGridID";
            //DeptGrid.AjaxEvents.Command.Event += new ComponentAjaxEvent.AjaxEventHandler(EditTraining);
            RowSelectionModel DeptPeopleGridSelModel = new RowSelectionModel();
            DeptPeopleGridSelModel.ID = deptName + "PeopleGridSelModel";
            DeptPeopleGridSelModel.SingleSelect = true;
            DeptPeopleGrid.SelectionModel.Add(DeptPeopleGridSelModel);
            DeptPeopleGrid.StoreID = DepartmentPeopleStore.ID;
            DeptPeopleGrid.Title = "<b>Pracownicy:</b> " + dept.Name;
    
            PagingToolbar DeptPeopleGridPagingToolbar = new PagingToolbar();
            DeptPeopleGridPagingToolbar.ID = deptName + "PeopleGridPagingToolbar";
            DeptPeopleGridPagingToolbar.PageSize = 10;
            DeptPeopleGridPagingToolbar.StoreID = DepartmentPeopleStore.ID;
            DeptPeopleGrid.BottomBar.Add(DeptPeopleGridPagingToolbar);
    
            Column DeptPeopleGridUserNameCol = new Column();
            DeptPeopleGridUserNameCol.Header = "Imię i nazwisko";
            DeptPeopleGridUserNameCol.DataIndex = "Name";
            DeptPeopleGrid.ColumnModel.Columns.Add(DeptPeopleGridUserNameCol);       
    
            CommandColumn DeptPeopleGridUserShowDetailsTrasCol = new CommandColumn();
            GridCommand DeptPeopleGridUserShowDetailsTrasColCommand = new GridCommand();
            DeptPeopleGridUserShowDetailsTrasColCommand.CommandName = "ShowUserTras";
            DeptPeopleGridUserShowDetailsTrasColCommand.Text = "Pokaż szczegóły";
            DeptPeopleGridUserShowDetailsTrasColCommand.Icon = Icon.VcardEdit;
            DeptPeopleGridUserShowDetailsTrasCol.Commands.Add(DeptPeopleGridUserShowDetailsTrasColCommand);
            DeptPeopleGrid.ColumnModel.Columns.Add(DeptPeopleGridUserShowDetailsTrasCol);
    
            DeptPeopleGrid.AjaxEvents.Command.Event += new ComponentAjaxEvent.AjaxEventHandler(ShowPersonTrasDetails);
            DeptPeopleGrid.AjaxEvents.Command.Before = "Coolite.Ext.Mask.show({msg:'Ładuję...'});";
            DeptPeopleGrid.AjaxEvents.Command.EventMask.ShowMask = true;
            DeptPeopleGrid.AjaxEvents.Command.EventMask.Target = MaskTarget.CustomTarget;
            DeptPeopleGrid.AjaxEvents.Command.EventMask.CustomTarget = "#{ViewPort1}";  
         
            Coolite.Ext.Web.Parameter DeptPeopleGridParam = new Coolite.Ext.Web.Parameter();
            DeptPeopleGridParam.Name = "usId";
            DeptPeopleGridParam.Value = "this.getSelectionModel().getSelected().id";
            DeptPeopleGridParam.Mode = ParameterMode.Raw;
            DeptPeopleGrid.AjaxEvents.Command.ExtraParams.Add(DeptPeopleGridParam);
            
            //code with creating the tab is removed for clarity (tab is created in this method)
            CenterPanel.Tabs.Add(deptTab); // centerPanel is TabPanel it sits in .aspx file
            deptTab.Hidden = true;
    
    
            DeptPeopleGrid.Controls.Add(DepartmentPeopleStore);
            DepartmentPeopleStore.DataSource = dept.GetAllUsersInHierarchy();
            DepartmentPeopleStore.DataBind();
        }
    so when i am clicking a button in command column after some loading the error message is shown "Could not find control with id='describe above tab id'...".

    Without !IsAjaxRequest statement everything is working, but becouse i am generating many tabs, grids and stores at page load it take some time finsh AjaxRequest.

    I want to make my app faster so what i can do to keep those generated tabs and grids present after AjaxRequestt?

    sorry for my english

    thx in advance for help
    rgds
    roszman
    Last edited by geoffrey.mcgill; Jul 21, 2010 at 6:44 PM. Reason: please use [code] tags
  2. #2
    Hi roszman,

    The issue is caused because the control is not recreated during the AjaxEvent. In your code sample the event handler is created during the Page_Load event, but since it is not re-created during the following AjaxEvent, the framework throws and Exception because it does not exist.

    You'll need to recreate your components on each request, preferably early in the page life-cycle, such as during OnInit.

    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    hi

    thx for reply, i will try that

Similar Threads

  1. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM
  2. [CLOSED] Creating Dynamic Tab in VB Code-Behind
    By Bert76 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 07, 2011, 3:31 PM
  3. [CLOSED] Problem creating TableLayout in code-behind
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 25, 2010, 1:29 PM
  4. Problem with Dynamic GridPanels
    By sindevil0010 in forum 1.x Help
    Replies: 1
    Last Post: Aug 27, 2010, 1:37 AM
  5. [CLOSED] Creating tabs on the fly in an AjaxEvent
    By alexp in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 17, 2009, 12:39 PM

Posting Permissions