protected void Page_Load(object sender, EventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (State == null || State.Count <= 2) { Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "timeOut('../Default.aspx');", true); return; }

        GetGoogleDocsInfoHelp.Attributes.Add("onclick", PopupHelper.GeneratePopupScript(
                "../Help/PageData/GetGoogleDocsInfoHelp.htm", 350, 700, false, false, false, true));
        GetGoogleDocsInfoHelp2.Attributes.Add("onclick", PopupHelper.GeneratePopupScript(
                 "../Help/PageData/GetGoogleDocsInfoHelp.htm", 350, 700, false, false, false, true));

        DataSources DS = new DataSources();
        if (!IsPostBack)
        {
            string id = Request.QueryString.Get("id");
            if (id != null)
            {
                State["DataSourceID"] = DataSourceID.Text = id;
                 State["DBConnectionString"] = DS.GetDataSourceDatabaseConnection(State);
            }

            if (!State["AccountType"].ToString().Contains("google_apps"))
            {
                if ( State["DBConnectionString"] != null)
                {
                    string[] parts =  State["DBConnectionString"].ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    foreach (string part in parts)
                    {
                        string[] parms = part.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        switch (parms[0])
                        {
                            case "username":
                                Username.Text = parms[1];
                                break;
                            case "password":
                                Password.Text = parms[1];
                                break;
                            case "spreadsheet":
                                AccountSpreadsheets.Items.Clear();
                                AccountSpreadsheets.Items.Add(new RadComboBoxItem("Select Spreadsheet ->", "->"));
                                AccountSpreadsheets.Items.Add(new RadComboBoxItem(parms[1], parms[1]));
                                AccountSpreadsheets.SelectedIndex = 1;
                                break;
                         }
                    }
                    SpreadsheetLink.Text = DS.GetSpreadsheetLinkFromConnectionString(State["DBConnectionString"].ToString());
                }
            }

            else if ( State["AccountType"].ToString().Contains("google_apps"))
            {
                ContentMultiPage.SelectedIndex = 1;
                GDocs gDocs = new GDocs();
                string ret = gDocs.GetSpreadsheets(State, Spreadsheets);
                if (ret != "OK")
                {
                    SaveGoogleDocsInfoMessage.Text = "There was an error in getting spreadsheet info from your Google Apps. " + ret;
                    return;
                }

                if ( State["DBConnectionString"] != null)
                {
                    string[] parts =  State["DBConnectionString"].ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    foreach (string part in parts)
                    {
                        string[] parms = part.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        switch (parms[0])
                        {
                            case "spreadsheet":
                                Spreadsheets.SelectedValue = parms[0];
                                break;
                        }
                    }
                    SpreadsheetLink.Text = DS.GetSpreadsheetLinkFromConnectionString(State["DBConnectionString"].ToString());
                }
            }
        }
    }