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;
        }
    }
    protected void AcceptPageName_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        try
        {
            ClearMessages();
            if (SavedCanvasHtml.Text.Length > 0)
                SavePage();
            string next_page = PageName.Text.Trim().Replace(" ", "_");
            PageName.Text = "";

            if (!CheckPageName(CurrentApp.SelectedValue, next_page))
            {
                return;
            }
            XmlUtil x_util = new XmlUtil();

            x_util.RenameAppPage(State,  State["SelectedAppPage"].ToString(), next_page);
            if (x_util.IsCurrentPageNameUsed(State))
            {
                x_util.ReplacePageNameUsedInSubmits(State, State["SelectedAppPage"].ToString(),next_page);
                Message.Text = "The new page name was changed for all actions that refer to it in your app.";
            }
            AppPages.SelectedValue = next_page;
            State["SelectedAppPage"] = next_page;
            PageName.Text = State["SelectedAppPage"].ToString();

            State["DoSavePage"] = true;
            InitAppPages();

            PagePanel.Style.Value = PagePanelStyle;
            ShowPage(next_page);
        }
        catch (Exception ex)
        {
             util.LogError(State, ex);
            Message.Text = "Internal Error: " + ex.Message + ": " + ex.StackTrace;
        }
    }