[CLOSED] [1.0] Accessing instance of store defined in custom server control

  1. #1

    [CLOSED] [1.0] Accessing instance of store defined in custom server control

    We have a grid that we are trying to convert to a server control so that we can use it across multiple pages, to encapsulate everything we are defining the store in that class as well.

    We are having an issue with this though because there is another control on our page that uses that store (by way of property). When we try and load the page, it throws an exception that the store isnt defined. Is there anything we need to be doing special to control the rendering order so that the store is defined before?

    I'll try and post a small snippet of what we're doing below.. i've removed alot of the irrelevant code from the example

    Markup
    
    <ext:SearchField 
     ID="txtSearch" 
     runat="server" 
     EmptyText="Search Employee/Report ID" 
     StoreID="stoStuffToSearch"
     Width="185" 
     ParamName="employeeNameReportId" />
    
    <ext:ManagerApprovalGrid runat="server" />
    C#
    
    public class ManagerApprovalGrid : GridPanel
     {
    public ManagerApprovalGrid()
            {
                this.ID = "grdApproval";
                this.Height = 370;
                this.AutoExpandColumn = "ProjectName";
                this.AutoExpandMin = 100;
                this.AutoExpandMax = 5000;
                this.ColumnLines = true;
                this.MemoryIDField = "ExpenseItemOID";
                this.SelectionMemory = SelectionMemoryMode.Enabled;
    
    
                this.TopBar.Add(BuildTopBar());
                this.SelectionModel.Add(BuildSelectionModel());
                BuildColumnModel();
                this.View.Add(BuildView());
    
    
                this.LoadMask.Msg = "Loading Expense Items";
                this.LoadMask.ShowMask = true;
    
    
                this.SaveMask.Msg = "Saving Selections...";
                this.SaveMask.ShowMask = true;
    
    
                this.Listeners.BeforeRender.Handler = "this.colModel.setRenderer(0, renderSelectColumn);";
                this.Listeners.AfterRender.Fn = "setGridColumnEvents";
                this.Listeners.Command.Fn = "handleGridCommand";
                this.Listeners.CellClick.Fn = "grdApproval_CellClick";
    
    
                this.Plugins.Add(BuildCellToolTopPlugin());
    
    
                this.Init += new System.EventHandler(ManagerApprovalGrid_Init);
            }
    
    
    
            private Store BuildStore()
            {
                Store store = new Store();
    
    
                store.ID = "stoStuff";
                store.GroupField = "ReportID";
                store.RemoteSort = true;
                store.RemoteGroup = true;
                store.PruneModifiedRecords = false;
                store.WarningOnDirty = false;
                store.RefreshAfterSaving = RefreshAfterSavingMode.Always;
                store.SerializationMode = SerializationMode.Complex;
    
    
                store.UpdateProxy.Add(
                    new HttpWriteProxy
                    {
                        Url="../UpdateProxy",
                        Method = HttpMethod.POST
                    }
                );
    
    
                store.Proxy.Add(
                    new Ext.Net.HttpProxy
                    {
                        Url = "../Proxy"
                    }
                );
    
    
                store.BaseParams.Add(new Parameter
                    {
                        Name = "start",
                        Mode = ParameterMode.Raw,
                        Value = "0"
                    });
                store.BaseParams.Add(new Parameter
                    {
                        Name = "limit",
                        Mode = ParameterMode.Raw,
                        Value = "#{pagingToolbar}.pageSize"
                    });
                store.BaseParams.Add(new Parameter
                    {
                        Name = "sort",
                        Mode = ParameterMode.Raw,
                        Value = "#{ddlSortBy}.getValue()"
                    });
                store.BaseParams.Add(new Parameter
                    {
                        Name = "dir",
                        Mode = ParameterMode.Raw,
                        Value = "#{btnSortDir}.pressed ? 'DESC' : 'ASC'"
                    });
    
    
                store.Reader.Add(
                        new Ext.Net.JsonReader
                        {
                            IDProperty = "ID",
                            Root = "Items",
                            TotalProperty = "Total",
                            Fields =
                            {
                                //Records...
                            }
                        }
                    );
    
    
                RecordField incurredDate = new RecordField("Incurred");
                incurredDate.Convert.Fn = "Ext.util.decodeMSDate";
    
    
                store.Listeners.CommitDone.Fn = "stoStuff_CommitDone";
    
    
                return store;
            }
    
    }
    Last edited by geoffrey.mcgill; Jul 07, 2010 at 2:23 AM.
  2. #2

    RE: [1.0] Accessing instance of store defined in custom server control

    Hi,

    I think you're missing a few critical bits from the code samples. Where is .BuildStore() called and how is the Store added to the controls collection|Page|GridPanel?


    How about adding the Store to the GridPanels .Store property.


    Example


    this.Store.Add(this.BuildStore());

    You should be able to add that line near the end of the constructor.


    Hope this helps.


    Geoffrey McGill
    Founder
  3. #3

    RE: [1.0] Accessing instance of store defined in custom server control



    Hey Geoff,

    I must have removed that debugging before posting. I added it back and i'm still getting the issue.

    I also added the id to the server control now.

    <grid:ManagerApprovalGrid ID="grdApproval" runat="server" />

    Here is my updated constructor
                this.Height = 370;
                this.AutoExpandColumn = "ProjectName";
                this.AutoExpandMin = 100;
                this.AutoExpandMax = 5000;
                this.ColumnLines = true;
                this.MemoryIDField = "ExpenseItemOID";
                this.SelectionMemory = SelectionMemoryMode.Enabled;
    
    
                this.TopBar.Add(BuildTopBar());
                this.SelectionModel.Add(BuildSelectionModel());
                BuildColumnModel();
                this.View.Add(BuildView());
                this.Store.Add(BuildStore());
    
    
                this.LoadMask.Msg = "Loading Expense Items";
                this.LoadMask.ShowMask = true;
    
    
                this.SaveMask.Msg = "Saving Selections...";
                this.SaveMask.ShowMask = true;
    
    
                this.Listeners.BeforeRender.Handler = "this.colModel.setRenderer(0, renderSelectColumn);";
                this.Listeners.AfterRender.Fn = "setGridColumnEvents";
                this.Listeners.Command.Fn = "handleGridCommand";
                this.Listeners.CellClick.Fn = "grdApproval_CellClick";
    
    
                this.Plugins.Add(BuildCellToolTopPlugin());
  4. #4

    RE: [1.0] Accessing instance of store defined in custom server control

    Thanks for the update. Is it working now? If no, try and strip out as much of the properties (ie. Listeners) as you can, and get to a point where at least the GridPanel + Store render.

    Geoffrey McGill
    Founder
  5. #5

    RE: [1.0] Accessing instance of store defined in custom server control

    It's still not working. i'll try and put together a sample recreating it this weekend.

    The main issue i see is that I have a control above the grid (the searchfield in this case) that references the instance of the store. When i went to encapsulate everything related to the grid in a control, the store moved from being declared above this searchfield, to below it (inside the grid)

    Because of this it throws an exception that the store is undefined because it hits the search field js before the grid/store js.

    We might be able to modify those controls to just accept a storeid instead of an actual store, and then reference it from the StoreManager by that id?
  6. #6

    RE: [1.0] Accessing instance of store defined in custom server control

    Hi,

    What about to use
    this.Page.Form.Controls.AddAt(0, this.BuildStore());

    and use StoreID property of the grid in the BeforeClientInit server side event
    this.StoreID = this.store.ClientID

  7. #7

    RE: [1.0] Accessing instance of store defined in custom server control



    Hey,

    We tried this friday but we keep getting the exception

    "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."

    Tried adding it to render since that's all that was really left but that threw a js exception.

            protected override void OnLoad(System.EventArgs e)
            {
                this.Page.Form.Controls.AddAt(0, this._store);
    
    
                base.OnLoad(e);
            }

    is there somewhere else I should be adding the control? the Page isn't initialized in the constructor so I couldn't add it there.
  8. #8

    RE: [1.0] Accessing instance of store defined in custom server control

    so I think we are just going to change the other two controls we have to no longer reference the instance of the store, but just to store the stringid of it and pull it from the StoreManager as needed.

    Thanks for the help guys!
  9. #9

    RE: [1.0] Accessing instance of store defined in custom server control

    Hi,

    I created small sample which demonstrates AddAt method for the Store
    <%@ Page Language="C#" %>
    
    <%@ 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">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Examples</title>
        
        <script runat="server">
            public class TestGrid : GridPanel
            {
                public TestGrid()
                {
                    this.ColumnModel.Columns.Add(new Column { Header = "Test", DataIndex="TestField" });
                }
                
                private Store store;            
                private Store BuildStore()
                {
                    if (this.store != null)
                    {
                        return this.store;
                    }
                    
                    Store store = new Store();
    
                    store.ID = "stoStuff";
                    
                    store.Reader.Add(
                            new Ext.Net.JsonReader
                            {                            
                                Fields =
                                {
                                    new RecordField("TestField")
                                }
                            }
                        );
    
                    this.store = store;
                    return store;
                }
                
                protected override void  OnLoad(EventArgs e)
                {
                     base.OnLoad(e);                                
                    this.EnsureChildControls();
                    this.StoreID = this.store.ClientID;
                }
    
                protected override void CreateChildControls()
                {
                    base.CreateChildControls();
    
                    this.Page.Form.Controls.AddAt(0, this.BuildStore());
                }            
            }
    
    
            protected void Page_Load(object sender, EventArgs e)
            {
                this.Page.Form.Controls.Add(new ComboBox { StoreID = "stoStuff" });
                this.Page.Form.Controls.Add(new TestGrid () );
            }    
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" ScriptMode="Debug" />
    
            
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] AjaxMethod in Custom Server Control
    By jon in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 30, 2016, 2:18 PM
  2. Custom Server Control Textfield
    By m_bo in forum 1.x Help
    Replies: 3
    Last Post: Mar 30, 2012, 9:21 AM
  3. [CLOSED] Creating custom control on server side
    By AnulekhaK in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 21, 2012, 10:15 AM
  4. Replies: 3
    Last Post: May 17, 2011, 9:11 AM
  5. Replies: 1
    Last Post: Nov 01, 2010, 9:00 PM

Posting Permissions