[CLOSED] Store in .aspx: Access to the Store from usercontrol

  1. #1

    [CLOSED] Store in .aspx: Access to the Store from usercontrol

    Hi everyone,

    I have an aspx which contains several usercontrols. Sometimes, several usercontrols need the same data from the data base (for example, "Cities" table), so I think it would be better (under performance point of view) if there is just one Store in aspx and the user controls read the data from that Store (instead of each usercontrol having its own Store loading each one the same data).

    So, how could the usercontrol access to the Store contained in aspx??

    Thank you in advance.
    Last edited by Daniil; Jan 17, 2014 at 10:27 AM. Reason: [CLOSED]
  2. #2
    Hi @jamesand,

    Quote Originally Posted by jamesand View Post
    So, how could the usercontrol access to the Store contained in aspx??
    Please clarify where do you need to access - on server or client sides?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @jamesand,



    Please clarify where do you need to access - on server or client sides?
    Hi Daniil, some of them on server and some of them on client.

    EDIT: The thing is that We are looking for better performance, so it would be great if the controls access the store at the time it is gonna be used, for example when a combobox is clicked or a gridview is shown. Is it possible? (It then will be done on server side, I guess)
    Last edited by jamesand; Jan 14, 2014 at 12:34 PM.
  4. #4
    To access a page's Store from a user control, you can create a property for a user control (named, for example, Store) and set it to the page's Store when you instantiate a user control.

    On client you can access a Store by its client id as usual.

    EDIT: The thing is that We are looking for better performance, so it would be great if the controls access the store at the time it is gonna be used, for example when a combobox is clicked or a gridview is shown. Is it possible? (It then will be done on server side, I guess)
    Yes, the idea is good. Though, please note that if you share the Store to, for example, two GridPanels, then filter the first GridPanel, that filtration will affect the second GridPanel as well. So, be careful.
  5. #5
    Quote Originally Posted by Daniil View Post
    Yes, the idea is good. Though, please note that if you share the Store to, for example, two GridPanels, then filter the first GridPanel, that filtration will affect the second GridPanel as well. So, be careful.
    Ok, noted. Thank you.
  6. #6
  7. #7
    Maybe, a method to assign a Store is better.

    Page
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <%@ Import Namespace="Work2" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[] 
                { 
                    new object[] { "test", "test" },
                    new object[] { "test", "test" },
                    new object[] { "test", "test" }
                };
    
                WebUserControl1 uc = (WebUserControl1)this.LoadControl("WebUserControl1.ascx");
                uc.AssignStore(this.Store1);
                this.Form.Controls.Add(uc);
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
             <ext:Store ID="Store1" runat="server">
                <Model>
                    <ext:Model runat="server">
                        <Fields>
                            <ext:ModelField Name="test1" />
                            <ext:ModelField Name="test2" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </form>
    </body>
    </html>
    User Control Markup
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="Work2.WebUserControl1" %>
    
    <ext:GridPanel ID="GridPanel1" runat="server">
        <ColumnModel runat="server">
            <Columns>
                <ext:Column runat="server" Text="Test 1" DataIndex="test1" />
                <ext:Column runat="server" Text="Test 2" DataIndex="test2" />
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
    User Control Code Behind
    namespace Work2
    {
        public partial class WebUserControl1 : System.Web.UI.UserControl
        {
            public void AssignStore(Ext.Net.Store store)
            {
                this.GridPanel1.StoreID = store.ID;
            }
        }
    }
  8. #8
    Hi Daniil, thank you for your response.

    It doesn't solve the problem. In this case, I don't want to assign the ID of the Store in codebehind, I want to retrieve the data stored in the Store. I want to retrieve Store.DataSource. Let me explain why:

    I configured my web site so some stores are initiated in the unique .aspx page of my site. In this .aspx page there are contained several .ascx. In some of them there are controls which need the same data, so that's the pourpose of having the stores contained all together in the same .aspx, so there will be just one reading to the database.
    But, in some of the controls, we do a filtering of the data of the database, and why do the filtering reading the database if we already have the table we need stored in the Store.

    I don't know if I explained myself. Sorry for my english.
  9. #9
    How big are those data that you are reading from the database?

    Maybe, it is an option to save it the Session global object.

    As for sharing a Store between the page and user controls, I think it won't help you much in your scenario.

    By the way, you are totally right that you are trying to reduce calls to a database.
  10. #10
    Quote Originally Posted by Daniil View Post
    Maybe, it is an option to save it the Session global object.
    I changed some code and opted to access the store in client side. Thank you anyway for your estimated help.

Similar Threads

  1. Replies: 2
    Last Post: Nov 15, 2012, 12:52 AM
  2. [CLOSED] ViewBag value in combobox store listener [aspx]
    By boris in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 22, 2012, 7:44 AM
  3. [CLOSED] Access Grid Data Store and manually store to database
    By macap in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 05, 2011, 8:52 AM
  4. Access store in parent page
    By pintun in forum 1.x Help
    Replies: 0
    Last Post: Apr 07, 2010, 7:40 AM
  5. Access to Store after PostBack...
    By myron in forum 1.x Help
    Replies: 3
    Last Post: May 07, 2009, 3:19 PM

Tags for this Thread

Posting Permissions