protected void AddLinkButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        LinkDateTextBox.Text = DateHandler.ToDateString(DateTime.Today);
        LinkTimeTextBox.Text = DateHandler.ToTimeString(DateTime.Now);
        LinkCategoryDropdownList.DataValueField = "CategoryRef";
        LinkCategoryDropdownList.DataTextField  = "CategoryName";
        LinkCategoryDropdownList.DataSource     = Category.GetCategoryList();
        LinkCategoryDropdownList.DataBind();

        LinkUserDropDownList.Items.Clear();
        LinkUserDropDownList.Items.Add(new ListItem("null", "0"));
        LinkUserDropDownList.Items.Add(new ListItem(user.UserName, user.UserRef.ToString()));
        LinkUserDropDownList.SelectedIndex = 1;

        LinkNameTextBox.Text   = "";
        LinkUrlTextBox.Text    = "";
        LinkClicksTextBox.Text = "0";
        LinkRatingTextBox.Text = "0";

        this.ViewState["EditLinkRef"] = 0;
        EditLinkPanel.Visible         = true;
        base.ShowModalBackground();
    }
    protected void EditButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (SelectedView == ViewMode.LinkSuggestion)
        {
            List <int> linkSuggestionRefList = GetPostCollection("SuggestionCheckBox");
            if (linkSuggestionRefList.Count > 0)
            {
                LinkSuggestion linkSuggestion = LinkSuggestion.GetOne(linkSuggestionRefList[0]);
                if (linkSuggestion == null)
                {
                    return;
                }

                LinkSuggestionDescriptionTextBox.Text = linkSuggestion.Description;
                LinkSuggestionUrlTextBox.Text         = linkSuggestion.LinkUrl;

                LinkSuggestionCategoryDropdownList.DataValueField = "CategoryRef";
                LinkSuggestionCategoryDropdownList.DataTextField  = "CategoryName";
                LinkSuggestionCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkSuggestionCategoryDropdownList.DataBind();

                try { LinkSuggestionCategoryDropdownList.SelectedValue = linkSuggestion.CategoryRef.ToString(); }
                catch { }

                this.ViewState["EditLinkSuggestionRef"] = linkSuggestion.LinkSuggestionRef;
                EditLinkSuggestionPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
        else if (SelectedView == ViewMode.LinkAdministration)
        {
            List <int> selectedLinkRefRefList = GetPostCollection("LinkSelectionCheckBox");
            if (selectedLinkRefRefList.Count > 0)
            {
                Link link = Link.GetOne(selectedLinkRefRefList[0]);
                if (link == null)
                {
                    return;
                }

                LinkDateTextBox.Text = DateHandler.ToDateString(link.LinkDate);
                LinkTimeTextBox.Text = DateHandler.ToTimeString(link.LinkDate);
                LinkNameTextBox.Text = link.LinkName;

                LinkCategoryDropdownList.DataValueField = "CategoryRef";
                LinkCategoryDropdownList.DataTextField  = "CategoryName";
                LinkCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkCategoryDropdownList.DataBind();

                try { LinkCategoryDropdownList.SelectedValue = link.CategoryRef.ToString(); }
                catch { }

                LinkUserDropDownList.Items.Clear();
                LinkUserDropDownList.Items.Add(new ListItem("null", "0"));

                if (link.UserRef != user.UserRef)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(user.UserName, user.UserRef.ToString()));
                }

                if (link.UserRef != null)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(link.UserName, link.UserRef.Value.ToString()));
                    LinkUserDropDownList.SelectedValue = link.UserRef.Value.ToString();
                }

                LinkUrlTextBox.Text    = link.LinkUrl;
                LinkClicksTextBox.Text = link.Clicks.ToString();
                LinkRatingTextBox.Text = Math.Round(link.Rating, 2).ToString();

                this.ViewState["EditLinkRef"] = link.LinkRef;
                EditLinkPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
    }