[CLOSED] Problem with portal and portlets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] Problem with portal and portlets

    There is a portal in my website, in which i add PortalColumns dynamically (to the "Items" property). To these PortalColumns Items i add Portlets, also dynamically. The portlets use autoload with LoadMode.IFrame to load urls into them. There is a window with fields the user can use to add or remove new items from the screen (portlets), choosing the url, title, etc and then clicking an "add" button. When the user adds a new item, i call a method in which i clear the portal's items and re-add them with the newly added one: there is a db table in which i record user's items. I call portal.Items.Clear(), then read the table and re-add them.

    The first problem is that this never updates the items in the screen. The only way to get the items updated is to do a postback.
    The second one is that if user adds more than 3 items (2 portal columns with 4 portlets), he gets an erros saying that 'System.Collections.ArrayList' can't be converted to 'System.Web.UI.Pair' in Ext.Net's ViewState.cs.

    If i do a postback the portlet is loaded normally.
    I've seen a few posts that seemed to be related to the second problem, and tried the solutions provided, but none seemed to work (like calling DoLayout(), using unique ids, etc).

    Please, see if you can help me.
  2. #2
    Hello!

    Thanks a lot for detailed description of your problem. But providing us with a sample code reproducing the issue would be much better. Could you provide?
    Last edited by Daniil; Aug 13, 2010 at 8:46 AM.
  3. #3
    Sure, there it its:

        private void LoadPortlets()
        {
            ...
            
            portal.Items.Clear();
            
            DataTable dataTable = LoadDataTableWithRegisteredPortlets();
            Int32 i = 0;
            for (; i < dataTable.Rows.Count; i += 2)
            {
                Portlet portlet1 = CreatePortLet(dataTable.Rows[i]["TITLE"].ToString(), dataTable.Rows[i]["URL"].ToString());
                Portlet portlet2 = null;
                if ((i + 1) < dataTable.Rows.Count)
                {
                    portlet2 = CreatePortLet(dataTable.Rows[i + 1]["TITLE"].ToString(), dataTable.Rows[i + 1]["URL"].ToString());
                }
                portal.Items.Add(CreateportalColumn(portlet1, portlet2));
            }
    
            ...
    
        }
    
    private Portlet CreatePortLet(String title, String url)
        {
            Portlet portlet = new Portlet();
            portlet.Title = title;
            portlet.AutoHeight = true;
            portlet.Frame = true;
            portlet.AutoLoad.Url = url;
            portlet.AutoLoad.ShowMask = true;
            portlet.AutoLoad.Mode = LoadMode.IFrame;
            portlet.AutoLoad.MaskMsg = "Loading" + title + "...";
    
            return portlet;
        }
        
        private PortalColumn CreateportalColumn(Portlet item1, Portlet item2)
        {
            PortalColumn portalColumn = new PortalColumn()
            {
                Layout = "Anchor",
                AutoHeight = true,
                StyleSpec = "padding:5px 0 5px 5px",
                ColumnWidth = 0.33
            };
    
            portalColumn.Items.Add(item1);
            if (item2 != null)
                portalColumn.Items.Add(item2);
            return portalColumn;
        }
    in page_load and whenever user creates a new portlet (button click direct event), i call LoadPortlets().
    Last edited by geoffrey.mcgill; Aug 12, 2010 at 10:28 PM. Reason: please use [CODE] tags
  4. #4
    So, Daniil... Any hint? I'm really needing some help with this.
  5. #5
    Hi,

    During DirectEvent you have to use special methods to render new controls: Render, AddTo, InsertTo
    Please see the following sample which demonstrates how to add portlets (see Top toolbar buttons)
    <%@ Page Language="C#" %>
    <%@ Import Namespace="Ext.Net.Utilities" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                string text = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.";
    
                this.ResourceManager1.RegisterClientScriptBlock("text", string.Format("var text=\"{0}\";", text));
    
                foreach (Portlet portlet in ControlUtils.FindControls<Portlet>(this.Page))
                {
                    portlet.Html = "={text}";
                    portlet.Tools.Add(new Tool(ToolType.Close, string.Concat(portlet.ClientID, ".hide();"), "Close Portlet"));
                }
            }
    
            foreach (Portlet portlet in ControlUtils.FindControls<Portlet>(this.Page))
            {
                portlet.DirectEvents.Hide.Event += Portlet_Hide;
                portlet.DirectEvents.Hide.EventMask.ShowMask = true;
                portlet.DirectEvents.Hide.EventMask.Msg = "Saving...";
                portlet.DirectEvents.Hide.EventMask.MinDelay = 500;
                
                portlet.DirectEvents.Hide.ExtraParams.Add(new Ext.Net.Parameter("ID", portlet.ClientID));
            }
        }
    
        protected void Portlet_Hide(object sender, DirectEventArgs e)
        {
           X.Msg.Alert("Status", e.ExtraParams["ID"] + " Hidden").Show();
        }
    
        protected void AddColumn1(object sender, DirectEventArgs e)
        {
            Portlet p = new Portlet { 
                Title = "New portlet in column1",
                Html = DateTime.Now.ToShortTimeString()
            };
    
            //must be called during DirectEvent only (if X.IsAjaxRequest == true)
            p.AddTo(Portal1_Column1);
        }
    
        protected void AddColumn2(object sender, DirectEventArgs e)
        {
            Portlet p = new Portlet
            {
                Title = "New portlet in column2",
                Html = DateTime.Now.ToShortTimeString()
            };
    
            //must be called during DirectEvent only (if X.IsAjaxRequest == true)
            p.InsertTo(0, Portal1_Column2);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Portal in TabPanel - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" /> 
        
        <style type="text/css">
            .x-column-padding{
                padding: 10px 0px 10px 10px;
            }
            
            .x-column-padding1{
                padding: 10px;
            }
        </style>  
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:Viewport runat="server">
                <Items>
                    <ext:BorderLayout runat="server">
                        <West 
                            Collapsible="true" 
                            Split="true" 
                            MinWidth="175" 
                            MaxWidth="400" 
                            MarginsSummary="5 0 5 5" 
                            CMarginsSummary="5 5 5 5">
                            <ext:Panel runat="server" Title="West" Width="200">
                                <Items>
                                    <ext:AccordionLayout runat="server" Animate="true">
                                        <Items>
                                            <ext:Panel 
                                                runat="server" 
                                                Border="false" 
                                                Collapsed="true" 
                                                Icon="Note"
                                                AutoScroll="true"
                                                Title="Content"
                                                Html="={text}"
                                                Padding="5"
                                                />
                                            <ext:Panel
                                                runat="server" 
                                                Border="false" 
                                                Collapsed="true" 
                                                Icon="FolderWrench" 
                                                AutoScroll="true"
                                                Title="Settings"
                                                Html="={text}"
                                                Padding="5"
                                                />
                                        </Items>
                                    </ext:AccordionLayout>
                                </Items>
                            </ext:Panel>
                        </West>
                        <Center MarginsSummary="5 5 5 0">
                            <ext:TabPanel runat="server" ActiveTabIndex="0" Title="TabPanel">
                                <Items>
                                    <ext:Panel runat="server" Title="Tab 1" Layout="Fit">
                                        <TopBar>
                                            <ext:Toolbar runat="server">
                                                <Items>
                                                    <ext:Button runat="server" Text="Add to end of the first column">
                                                        <DirectEvents>
                                                            <Click OnEvent="AddColumn1" />
                                                        </DirectEvents>
                                                    </ext:Button>
                                                    
                                                    <ext:Button runat="server" Text="Add to begin of the second column">
                                                        <DirectEvents>
                                                            <Click OnEvent="AddColumn2" />
                                                        </DirectEvents>
                                                    </ext:Button>
                                                </Items>
                                            </ext:Toolbar>
                                        </TopBar>
                                        <Items>
                                            <ext:Portal runat="server" Border="false" Layout="Column">
                                                <Items>
                                                    <ext:PortalColumn 
                                                        ID="Portal1_Column1"
                                                        runat="server" 
                                                        Cls="x-column-padding"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet1" runat="server" Title="Another Panel 1" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                    <ext:PortalColumn 
                                                        ID="Portal1_Column2"
                                                        runat="server" 
                                                        Cls="x-column-padding"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet2" runat="server" Title="Panel 2" />
                                                            <ext:Portlet ID="Portlet3" runat="server" Title="Another Panel 2" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                    <ext:PortalColumn 
                                                        runat="server" 
                                                        Cls="x-column-padding1"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet4" runat="server" Title="Panel 3" />
                                                            <ext:Portlet ID="Portlet5" runat="server" Title="Another Panel 3" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                </Items>
                                            </ext:Portal>
                                        </Items>
                                    </ext:Panel>
                                    <ext:Panel runat="server" Title="Tab 2" Layout="Fit">
                                        <Items>
                                            <ext:Portal runat="server" Border="false" Layout="Column">
                                                <Items>
                                                    <ext:PortalColumn 
                                                        runat="server" 
                                                        Cls="x-column-padding"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet6" Title="Panel 3" runat="server" />
                                                            <ext:Portlet ID="Portlet7" Title="Another Panel 3" runat="server" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                    <ext:PortalColumn 
                                                        runat="server" 
                                                        Cls="x-column-padding"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet8" Title="Panel 2" runat="server" />
                                                            <ext:Portlet ID="Portlet9" Title="Another Panel 2" runat="server" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                    <ext:PortalColumn 
                                                        runat="server" 
                                                        Cls="x-column-padding1"
                                                        ColumnWidth=".33"
                                                        Layout="Anchor">
                                                        <Items>
                                                            <ext:Portlet ID="Portlet10" Title="Another Panel 1" runat="server" />
                                                        </Items>
                                                    </ext:PortalColumn>
                                                </Items>
                                            </ext:Portal>  
                                        </Items>                                  
                                    </ext:Panel>
                                </Items>
                            </ext:TabPanel> 
                        </Center>
                    </ext:BorderLayout>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
  6. #6
    Ok, i'm beginning to figure it out. Now i can add the items, but:

    i want to have 3 columns with 2 portlets each. Then, if i try to clear them all and re-add the items, they won't get cleared, don't know why, and i'll end up with duplicate portlets (is there a similar ajaxrequest only method for clearing them?). I also can't add only the portlet that the user is inserting, because the item count of the columns is always 0, so the portlet will always be added to the first column, and as i can't read the already added portlets i can't validate if he is entering a duplicate portlet either.

    Any hint?

Similar Threads

  1. [CLOSED] [1.0] Dropping portlets into an empty portal...
    By betamax in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 26, 2010, 6:38 PM
  2. [CLOSED] [1.0] Portal does not show portlets when scrolling
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 18, 2010, 2:01 PM
  3. Dynamic portal and portlets in code behind
    By Sofficino in forum 1.x Help
    Replies: 1
    Last Post: Jun 08, 2009, 4:42 AM
  4. Replies: 2
    Last Post: Jan 14, 2009, 3:19 PM
  5. [CLOSED] Create Stateful Portal - Save Position and Collapse of Portlets
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 16, 2008, 7:26 PM

Tags for this Thread

Posting Permissions