[CLOSED] How to remove Controls from a ContentControls collection in code-behind?

  1. #1

    [CLOSED] How to remove Controls from a ContentControls collection in code-behind?

    This question is probably related to a recent question I asked:
    http://forums.ext.net/showthread.php...lling-the-data

    However, in this case I am not populating a Store, but a ContentControl collection, see this thread:
    http://forums.ext.net/showthread.php...in-code-behind

    So in short: I am adding a UserControl (CoreComment) to a ContentControl collection (as can be seen in the thread linked above).

    Each time I change the "object" (from a Combobox) I should populate the ContentControl with one instance of my CoreComment for each comment that that object has. But I first need to Clear it from previous UserControl, then populate. I cant seem to get that to work. I try this:
    this.PanelComments.ContentControls.Clear();
    
    foreach(CoreCommons.System.Comment c in cg.Reply_Comments)
    {
        WebApplicationExtNetTest.Secure.UserControls.CoreComment cc = (WebApplicationExtNetTest.Secure.UserControls.CoreComment)this.LoadControl("/Secure/UserControls/CoreComment.ascx");
        cc._Comment = c;
        this.PanelComments.ContentControls.Add(cc);
    }
    this.PanelComments.UpdateContent();
    But then usually nothing shows up at all - the Panel is just empty (which reminds me of this post).

    Any ideas?

    Good night =)
    Last edited by geoffrey.mcgill; May 18, 2011 at 6:47 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Well, when you change .ContentControls() during DirectEvent, these changes disappear during another DirectEvent, in other words - .ContentControls() controls are rendered by .UpdateContent() and that's all that happens.

    So, I'm not sure what you mean and, seems, can't reproduce. Here is my test case.

    Example .aspx
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Select(object sender, DirectEventArgs e)
        {
            TestUserControl c = (TestUserControl)LoadControl("TestUserControl.ascx");
            c.Text = e.ExtraParams["text"];
            this.Panel1.ContentControls.Add(c);
            this.Panel1.UpdateContent();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:ComboBox ID="ComboBox1" runat="server">
            <Items>
                <ext:ListItem Text="Item 1" Value="1" />
                <ext:ListItem Text="Item 2" Value="2" />
            </Items>
            <DirectEvents>
                <Select OnEvent="Select">
                    <ExtraParams>
                        <ext:Parameter Name="text" Value="record.data.text" Mode="Raw" />
                    </ExtraParams>
                </Select>    
            </DirectEvents>
        </ext:ComboBox>
        <ext:Panel ID="Panel1" runat="server" />
        </form>
    </body>
    </html>
    Example .ascx
    <%@ Control Language="C#" ClassName="TestUserControl" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        public string Text { get; set; }    
    </script>
    
    <ext:Label runat="server" Text="<%# this.Text %>" AutoDataBind="true" />
    Please provide a simplified samples how to reproduce the issue you described.

    By the way, don't forget that .UpdateContent() makes rough replacing html with new one and doesn't destroy widgets - memory leaks. The following sample demonstrates the technique how to avoid it:
    https://examples1.ext.net/#/XRender/...UpdateContent/
  3. #3
    What I mean is:

    Take your test sampel, add a Button that completely removes the added UserControls, so that they are gone.

    The link you posted doesnt really help me. I think?

    (I cannot run your sample it seems, it doesnt detect the Property "Text")
  4. #4
    Quote Originally Posted by wagger View Post
    Take your test sampel, add a Button that completely removes the added UserControls, so that they are gone.
    The link you posted doesnt really help me. I think?
    You can just call
    Panel1.body.update()
    to clear html, but, as I said, it doesn't destroy widgets. How to destroy you will find in the example I mentioned:
    https://examples1.ext.net/#/XRender/...UpdateContent/

    Quote Originally Posted by wagger View Post
    (I cannot run your sample it seems, it doesnt detect the Property "Text")
    Hmm, I have tested the example again and it appears to be working fine...

Similar Threads

  1. Replies: 2
    Last Post: Aug 10, 2012, 10:15 AM
  2. Remove gridfilters generated from code behind
    By mkshields9w57 in forum 1.x Help
    Replies: 1
    Last Post: Jun 04, 2012, 3:27 AM
  3. Replies: 3
    Last Post: May 21, 2010, 12:42 AM
  4. Replies: 3
    Last Post: Jan 28, 2010, 3:36 PM
  5. remove dynamic controls
    By raks in forum 1.x Help
    Replies: 0
    Last Post: May 13, 2009, 10:34 AM

Posting Permissions