[CLOSED] Difference Store behaviour Usercontrol (.ASCX) vs Class (.CS)

  1. #1

    [CLOSED] Difference Store behaviour Usercontrol (.ASCX) vs Class (.CS)

    Hi,


    i had to encapsulate a grid out of an ascx file into a class in order to use the same grid in different ascx files.


    now on every directmethod of any control anywhere on the same page lifecycle starts (including the grid-control's one) and the store gets empty, eventhough it was filled properly. while embedded in ascx markup same directmethods didnt clear the store.


    what is the difference between ascx-control-id-bevaviour and the same within a class file?
    why the store gets transferred (cleared) without any datasource/databind setting?




    public class ValueGridPanel : GridPanel
    {
        protected Store _storeValues;
        
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            _storeValues = new Store {ID = ID + "_storeValues"};
            JsonReader reader = new JsonReader { IDProperty = "ObjectId" };
            reader.Fields.Add(new RecordField("ObjectId"));
            reader.Fields.Add(new RecordField("Label"));
            _storeValues.Reader.Add(reader);
            Store.Add(_storeValues);
        }
    
    
        [DirectMethod]
        public void ChangeValue(string someId)
        {
            //Change values and rebind --> set is transferred correctly
            values = ...;
            _storeValues.DataSource = values;
            _storeValues.DataBind();
        }
    
    
        [DirectMethod]
        public void SomeOtherMethod()
        {
            // set is cleared without using datasource/databind
        }
    }
    Last edited by Daniil; Apr 25, 2012 at 10:00 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please ensure the code is wrapped in [CODE ] tags.
    Forum Guidelines For Posting New Topics
  3. #3
    hi daniil

    i have improved the code snipplet now.

    don't understand how the store takes place in viewstate-topic. While the store is in ascx-markup a directmethod doesn't clear the store, so on processing response the data remains anyhow (viewstate?).

    but if the store is created in codebehind (createchildcontrols) the store is allways cleared eventhough the ids are equal.

    enabling viewstate makes no sense for stores, right?

    _storeValues = new Store {ID = ID + "_storeValues", EnableViewState=true};
    any ideas?

    best regards
  4. #4
    Thanks for editing.

    Yes, I can't see any sense to set up EnableViewState for the Store.

    I am unable to reproduce the problem you described.

    I used the following sample basing on your code.

    Example Page
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <%@ Register Assembly="Work" Namespace="Work" TagPrefix="cc" %>
    
    <!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" />
            <cc:ValueGridPanel ID="ValueGridPanel1" runat="server" AutoHeight="true">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="ObjectId" DataIndex="ObjectId" />
                        <ext:Column Header="Label" DataIndex="Label" />
                    </Columns>
                </ColumnModel>
            </cc:ValueGridPanel>
            
            <ext:Button runat="server" Text="ChangeValue">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.ValueGridPanel1.ChangeValue('someId');" />
                </Listeners>
            </ext:Button>
    
            <ext:Button runat="server" Text="SomeOtherMethod">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.ValueGridPanel1.SomeOtherMethod();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Example Custom Control
    using System;
    using Ext.Net;
    
    namespace Work
    {
        public class ValueGridPanel : GridPanel
        {
            protected Store store;
    
            protected override void OnLoad(EventArgs e)
            {
                if (!Ext.Net.X.IsAjaxRequest)
                {
                    this.ResourceManager.AddDirectMethodControl(this);
                }
            }
    
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
                store = new Store { ID = ID + "_storeValues" };
                JsonReader reader = new JsonReader { IDProperty = "ObjectId" };
                reader.Fields.Add(new RecordField("ObjectId"));
                reader.Fields.Add(new RecordField("Label"));
                store.Reader.Add(reader);
                Store.Add(store);
            }
    
            [DirectMethod]
            public void ChangeValue(string someId)
            {
                store.DataSource = new object[] 
                { 
                    new 
                    { 
                        ObjectId = someId + "1", 
                        Label = "Label1"
                    },
                    new 
                    { 
                        ObjectId = someId + "2", 
                        Label = "Label2"
                    },
                };
                store.DataBind();
            }
    
            [DirectMethod]
            public void SomeOtherMethod()
            {
            
            }
        }
    }
  5. #5
    Thx for your quick response, I found the problem after reducing my window to the same as yours.

    The problem was that AutoDatabind clears the store but I "need" it in order to use Resource-Files for Title or all kinds of text - even on panels.

    The problem now isn't a big issue because I am able to set the text in the code behind.

    But it is problematically because I just noticed that all parent container's autodatabind properties clears the children stores, so I have to set all panel titles in code behind, and it is hard to find all cases.

    1) direct one

    <cc:ValueGridPanel ID="ValueGridPanel1" runat="server" AutoHeight="true" Title="<%#ResourcesGlobal.Entries%>" AutoDataBind="true">
    </cc:ValueGridPanel>
    2) parental one

    <Ext:Panel runat="server" Frame="false" Border="false" AutoDataBind="true">
        <Items>
            <cc:ValueGridPanel ID="ValueGridPanel1" runat="server">
            </cc:ValueGridPanel>
        </Items>
    </Ext:Panel>
    my version: 1.2.0.21133

    Any suggestions?

    best regards
  6. #6
    Confirmed, thanks for the report.

    The fix has been added to SVN, revision #3943.

Similar Threads

  1. Replies: 11
    Last Post: Jun 13, 2012, 4:53 PM
  2. Replies: 2
    Last Post: May 26, 2010, 11:58 PM
  3. [CLOSED] Difference between store's AutoLoadParams and BaseParams
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 16, 2009, 6:04 AM
  4. panel or tabpanel autoload usercontrol .ascx
    By manelj in forum 1.x Help
    Replies: 5
    Last Post: Feb 26, 2009, 11:21 AM
  5. Loading a UserControl (ascx) to a page
    By egodoy in forum 1.x Help
    Replies: 4
    Last Post: Dec 31, 2008, 11:40 AM

Tags for this Thread

Posting Permissions