PDA

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



jamesand
Jan 14, 2014, 10:13 AM
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.

Daniil
Jan 14, 2014, 12:18 PM
Hi @jamesand,



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?

jamesand
Jan 14, 2014, 12:34 PM
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)

Daniil
Jan 14, 2014, 2:00 PM
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.

jamesand
Jan 15, 2014, 12:39 PM
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.

jamesand
Jan 15, 2014, 2:06 PM

Daniil
Jan 15, 2014, 3:36 PM
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;
}
}
}

jamesand
Jan 16, 2014, 1:57 PM
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.

Daniil
Jan 17, 2014, 5:11 AM
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.

jamesand
Jan 17, 2014, 10:43 AM
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.