protected void DeletePage_Click(object sender, ImageClickEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        try
        {
            ClearMessages();
            XmlUtil x_util = new XmlUtil();
            int n_pages = x_util.GetAppPageCount(State);
            if (n_pages == 1)
            {
                Message.Text = "A saved application must have at least 1 page. You can rename this page.";
                return;
            }
            if (x_util.IsCurrentPageNameUsed(State))
            {
                Message.Text = "The page was deleted but note that it was referred to, by an action on another page.";
            }
            x_util.DeleteAppPage(State, State["SelectedAppPage"].ToString());
            AppPages.SelectedIndex = 0;
            InitAppPages();

            State["SelectedAppPage"] = AppPages.SelectedValue;
            PageName.Text = State["SelectedAppPage"].ToString();

            string html = x_util.GetAppPage(State, State["SelectedAppPage"].ToString());
            if (html.StartsWith("Error:"))
            {
                Message.Text += html;
                return;
            }
            State["PageHtml"] = html;
            PageName.Text = "";
        }
        catch (Exception ex)
        {
            util.LogError(State, ex);
            Message.Text = "Internal Error: " + ex.Message + ": " + ex.StackTrace;
        }
    }
    public void ShowPage(string page_name)
    {
        PageName.Text = page_name;
        try
        {
            XmlUtil x_util = new XmlUtil();

            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            if (State["SelectedDeviceType"] == null /*|| State["SelectedDeviceView"] == null*/)
            {
                string device_type = x_util.GetAppDeviceType(State);
                 State["SelectedDeviceType"] = device_type;
                // State["SelectedDeviceView"] = device_type;
                DeviceType.Text =  State["SelectedDeviceType"].ToString();
            }

            if (page_name != null)
            {
                string html = x_util.GetAppPage(State, page_name);
                if (html.StartsWith("Error:"))
                {
                    Message.Text = html;
                    return;
                }

                 State["PageHtml"] = html;
                 Util util = new Util();
                 if (State["DoSavePage"] != null)
                 {
                     State["DoSavePage"] = null;
                     util.SavePageImage(State, page_name, html);
                 }
                DefaultButtonImage.Text = util.GetDefaultButton(State);
            }
            else
            {
                 State["PageHtml"] = "";
                DefaultButtonImage.Text = ConfigurationManager.AppSettings["DefaultWebAppButtonImage"];
            }
        }
        catch (Exception ex)
        {
            Util util = new Util();
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            util.LogError(State, ex);
            Message.Text = "Internal Error: " + ex.Message + ": " + ex.StackTrace;
        }
    }