using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Telerik.Web.UI;

public partial class GridPersister : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button2.Enabled = Session[UserSelection.SelectedValue] != null ? true : false;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string user = UserSelection.SelectedValue;
        GridSettingsPersister SavePersister = new GridSettingsPersister(RadGrid1);
        Session[user] = SavePersister.SaveSettings();
        InfoImage.Visible = true;
        StatusLabel.Text = "Settings for " + user + " saved successfully!";
        Button2.Enabled = true;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string user = UserSelection.SelectedValue;
        GridSettingsPersister LoadPersister = new GridSettingsPersister(RadGrid1);

        if (Session[user] == null)
        {
            InfoImage.Visible = true;
            StatusLabel.Text = "No saved settings for this user were found!";
        }
        else
        {
            string settings = (string)Session[user];
            LoadPersister.LoadSettings(settings);
            RadGrid1.Rebind();
            InfoImage.Visible = true;
            StatusLabel.Text = "Settings for " + user + " were restored successfully!";
        }
    }
}