Store
To be able to use the
Store class, it is essential to activate the "
enableStore" property.
Store is a very powerful feature, that allows us to share information between client, server and serverEvents. Store es una funcionalidad muy potente que nos permitirá compartir información entre cliente, servidor y los serverEvents.
It works as a Dictionary<string, string>, with a "key" and a "value".
In the sample, we can see how store is used in Javascript (client event), in a serverEvent and in ASP.NET:
- Javascript: we can create the Store object like this: var store = new Store('{0}_Store'); We can do a "Set(key, value)" y un "Get(Key)" over the store variable. Is usually used in client events.
- serverEvents: when we are in a serverEvent, we can use the GAjaxServerEventArgs to call to e.store, that is a nomal Dictionary<string, string> from ASP.NET.
- ASP.NET: each GMaps instance has the Store property, wich can be used everytime we want at server's side (however the is advisable to use e.store inside the serverEvent).
Code.aspx
<cc1:GMap ID="GMap1" runat="server" enableServerEvents="true" enableStore="true" OnClick="GMap_Click" serverEventsType="AspNetPostBack" />
<cc1:GMap ID="GMap2" runat="server" enableServerEvents="true" enableStore="true" OnClick="GMap_Click" />
Code.aspx.cs
private static int _i = 0;
public static int i
{
get
{
return _i++;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GMap2.addListener(new GListener(GMap2.GMap_Id, GListener.Event.zoomend,
string.Format(@"
function(oldZoom, newZoom)
{{
var store = new Store('{0}_Store');
store.Set(Math.random(), oldZoom + '-' + newZoom);
}}
", GMap2.GMap_Id)));
GMap2.addControl(new GControl(GControl.preBuilt.SmallZoomControl));
}
GMap1.Store.Add(i.ToString(), DateTime.Now.ToString());
}
protected string GMap_Click(object s, GAjaxServerEventArgs e)
{
e.store[i.ToString()] = DateTime.Now.ToString();
return string.Format("alert('{0} Store items: {1}')", e.map, e.store.Count);
}