Fixed few bugs related to module.

May 20, 2008 at 10:34 AM
After we edit/delete/move a module it is unable to get the reference of the source and target ListBox correctly, it gets a null.
I have made the following code changes in bold to fix this.

protected void EditBtn_Click(Object sender, ImageClickEventArgs e)
        {
            String pane = ((ImageButton) sender).CommandArgument;

            ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("maincontent");
            ListBox _listbox = (ListBox)cph.FindControl(pane); //(ListBox)Page.FindControl(pane);

            if (_listbox.SelectedIndex != -1)
            {
                int mid = Int32.Parse(_listbox.SelectedItem.Value);

                // Redirect to module settings page
                Response.Redirect("ModuleSettings.aspx?mid=" + mid + "&tabid=" + tabId);
            }
        }



protected void DeleteBtn_Click(Object sender, ImageClickEventArgs e)
        {
            String pane = ((ImageButton)sender).CommandArgument;
           
            ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("maincontent");
            ListBox _listbox = (ListBox)cph.FindControl(pane);//(ListBox) Page.FindControl(pane);

            ArrayList modules = GetModules(pane);


            if (_listbox.SelectedIndex != -1)
            {
                ModuleItem m = (ModuleItem) modules[_listbox.SelectedIndex];
                if (m.ModuleId > -1)
                {
                    // config.DeleteModule() deletes the module in PortalCFG.xml
                    // and deletes any associated content in the database.
                    ASPNET.StarterKit.Portal.Configuration config = new ASPNET.StarterKit.Portal.Configuration();
                    config.DeleteModule(m.ModuleId);
                }
            }

            // Redirect to the same page to pick up changes
            Response.Redirect(Request.RawUrl);
        }



 protected void RightLeft_Click(Object sender, ImageClickEventArgs e)
        {
            String sourcePane = ((ImageButton) sender).Attributes["sourcepane"];
            String targetPane = ((ImageButton) sender).Attributes["targetpane"];

            ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("maincontent");
            ListBox sourceBox = (ListBox)cph.FindControl(sourcePane);//(ListBox) Page.FindControl(sourcePane);
            ListBox targetBox = (ListBox)cph.FindControl(targetPane);//(ListBox) Page.FindControl(targetPane);

            if (sourceBox.SelectedIndex != -1)
            {
                // get source arraylist
                ArrayList sourceList = GetModules(sourcePane);

                // get a reference to the module to move
                // and assign a high order number to send it to the end of the target list
                ModuleItem m = (ModuleItem) sourceList[sourceBox.SelectedIndex];

                // add it to the database
                ASPNET.StarterKit.Portal.Configuration config = new ASPNET.StarterKit.Portal.Configuration();
                config.UpdateModuleOrder(m.ModuleId, 998, targetPane);

                // delete it from the source list
                sourceList.RemoveAt(sourceBox.SelectedIndex);

                // Obtain portalId from Current Context
                PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];

                // reload the portalSettings from the database
                HttpContext.Current.Items["PortalSettings"] = new PortalSettings(portalSettings.PortalId, tabId);

                // reorder the modules in the source pane
                sourceList = GetModules(sourcePane);
                OrderModules(sourceList);

                // resave the order
                foreach (ModuleItem item in sourceList)
                {
                    config.UpdateModuleOrder(item.ModuleId, item.ModuleOrder, sourcePane);
                }

                // reorder the modules in the target pane
                ArrayList targetList = GetModules(targetPane);
                OrderModules(targetList);

                // resave the order
                foreach (ModuleItem item in targetList)
                {
                    config.UpdateModuleOrder(item.ModuleId, item.ModuleOrder, targetPane);
                }

                // Redirect to the same page to pick up changes
                Response.Redirect(Request.RawUrl);
            }
        }

Thanks.
Coordinator
May 23, 2008 at 11:19 AM
Fixed in Change Set 11962
Thanks:-)
Coordinator
Feb 19, 2012 at 1:10 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.