Anonymous user  |  Log in  |  Create Account

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.

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: the Store object can be created 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: in a serverEvent, the GAjaxServerEventArgs contains e.store, that is a nomal Dictionary<string, string> from ASP.NET. 
  • ASP.NET: each GMap instance has the Store property, which can be used anytime 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" />
<br />
<cc1:GMap ID="GMap2" runat="server" enableServerEvents="true" enableStore="true" OnClick="GMap_Click" />
Code.aspx.cs
private static int _i;

public static int Next
{
    get { return _i++; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        Page.Title = "Google Maps ASP.NET - " + lt_Titulo.Text;

        GMap2.Add(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.Add(new GControl(GControl.preBuilt.SmallZoomControl));
    }

    GMap1.Store.Add(Next.ToString(), DateTime.Now.ToString());
}

protected string GMap_Click(object s, GAjaxServerEventArgs e)
{
    e.store[Next.ToString()] = DateTime.Now.ToString();
    return string.Format("alert('{0} Store items: {1}')", e.map, e.store.Count);
}
Powered by Subgurim.NET