protected void Page_Load(object sender, EventArgs e)
    {
        int idFlight = util.GetIntParam(Request, "id", LogbookEntry.idFlightNone);

        if (idFlight == LogbookEntry.idFlightNone)
        {
            throw new MyFlightbookException("No valid ID passed");
        }

        Master.SelectedTab = tabID.tabLogbook;
        Master.Layout      = MasterPage.LayoutMode.Accordion;

        if (!IsPostBack)
        {
            // On a GET request, discard the cache and regenerate it.
            Session[KeyCacheData(idFlight)]   = null;
            Session[KeyCacheFlight(idFlight)] = null;
        }

        // Set up the object, either from cache or from db
        LoadLogbookEntry(idFlight);

        // for debugging, have a download option that skips all the rest
        if (util.GetIntParam(Request, "d", 0) != 0)
        {
            Response.Clear();
            Response.ContentType = "application/octet-stream";
            // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
            string szFilename    = String.Format(CultureInfo.InvariantCulture, "Data{0}-{1}-{2}", Branding.CurrentBrand.AppName, MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Replace(" ", "-");
            string szDisposition = String.Format(CultureInfo.InvariantCulture, "inline;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
            Response.AddHeader("Content-Disposition", szDisposition);
            Response.Write(m_le.FlightData);
            Response.End();
            return;
        }

        LoadData(m_le);

        // Set up any maps.
        mfbGoogleMapManager1.Map.SetAirportList(new AirportList(m_le.Route));
        mfbGoogleMapManager1.ShowMarkers = true;
        if (m_fd.HasLatLongInfo && m_fd.Data.Rows.Count > 1)
        {
            pnlMap.Visible = true;
            mfbGoogleMapManager1.Map.PathVarName             = PathLatLongArrayID;
            mfbGoogleMapManager1.Map.Path                    = m_fd.GetPath();
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = true;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = true;
        }
        else
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = false;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = false;
        }
        lnkZoomToFit.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;

        // Compute and store the distances, but only the first time since it doesn't change.
        if (!IsPostBack)
        {
            lblDistance.Text    = m_le.GetPathDistanceDescription(m_fd.ComputePathDistance());
            pnlDistance.Visible = lblDistance.Text.Length > 0;
            lblFlightDate.Text  = m_le.Date.ToShortDateString();
            lblFlightDesc.Text  = String.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", m_le.TailNumDisplay ?? string.Empty, m_le.Route, m_le.Comment);
        }

        UpdateChart();
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.SelectedTab = tabID.tabLogbook;

            // Set the multi-drag handles to use the hidden controls
            mhsClip.MultiHandleSliderTargets[0].ControlID = hdnClipMin.ClientID;
            mhsClip.MultiHandleSliderTargets[1].ControlID = hdnClipMax.ClientID;

            using (FlightData fd = new FlightData())
            {
                if (!IsPostBack)
                {
                    try
                    {
                        CurrentFlightID = InitRequestedFlightID();
                        if (CurrentFlightID == LogbookEntryCore.idFlightNone)
                        {
                            throw new MyFlightbookException("No valid ID passed");
                        }

                        InitPassedRestriction();

                        int iTab = GetRequestedTabIndex();
                        if (AccordionCtrl.Panes[iTab].Visible)
                        {
                            AccordionCtrl.SelectedIndex = iTab;
                        }

                        LogbookEntryDisplay led = CurrentFlight = LoadFlight(CurrentFlightID);
                        SetUpChart(DataTableForFlightData(fd), cmbXAxis, cmbYAxis1, cmbYAxis2);
                        UpdateChart(fd);
                        UpdateRestriction();

                        SetUpDownload(led);

                        // shouldn't happen but sometimes does: GetUserAircraftByID returns null.  Not quite sure why.
                        Aircraft ac = (new UserAircraft(led.User).GetUserAircraftByID(led.AircraftID)) ?? new Aircraft(led.AircraftID);
                        fmvAircraft.DataSource = new Aircraft[] { ac };
                        fmvAircraft.DataBind();

                        if (String.IsNullOrEmpty(CurrentFlight.FlightData) && TabIndexRequiresFlightData(iTab))
                        {
                            AccordionCtrl.SelectedIndex = DefaultTabIndex;
                        }
                    }
                    catch (MyFlightbookException ex)
                    {
                        lblPageErr.Text       = ex.Message;
                        AccordionCtrl.Visible = mfbGoogleMapManager1.Visible = pnlMap.Visible = pnlAccordionMenuContainer.Visible = pnlFlightDesc.Visible = false;
                        return;
                    }

                    if (DoDirectDownload())
                    {
                        return;
                    }
                }
                else
                {
                    UpdateChart(fd);
                }

                if (Restriction != null && !Restriction.IsDefault)
                {
                    mfbFlightContextMenu.EditTargetFormatString = mfbFlightContextMenu.EditTargetFormatString + "?fq=" + HttpUtility.UrlEncode(Restriction.ToBase64CompressedJSONString());
                }
                mfbFlightContextMenu.Flight = CurrentFlight;

                cmbAltUnits.SelectedValue   = ((int)fd.AltitudeUnits).ToString(CultureInfo.InvariantCulture);
                cmbSpeedUnits.SelectedValue = ((int)fd.SpeedUnits).ToString(CultureInfo.InvariantCulture);
                if (!fd.HasDateTime)
                {
                    lnkSendCloudAhoy.Visible = false;
                }

                SetUpMaps(fd);

                if (!IsPostBack)
                {
                    DistanceDisplay = CurrentFlight.GetPathDistanceDescription(fd.ComputePathDistance());
                    // Bind details - this will bind everything else.
                    CurrentFlight.UseHHMM = Viewer.UsesHHMM;    // make sure we capture hhmm correctly.
                    fmvLE.DataSource      = new LogbookEntryDisplay[] { CurrentFlight };
                    fmvLE.DataBind();
                }
            }
        }