protected void SaveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                //[{"name":"X_MODS~1","value":"X"},{"name":"X_MODS~2","value":"X"},{"name":"X_MODS~3","value":"X"},{"name":"X_MODS~4","value":"X"}]
                if (VariablesLB.SelectedItem != null)
                {
                    int                  selectedIndex = VariablesLB.SelectedIndex;
                    string               variableName  = VariablesLB.SelectedItem.Text;
                    string               variableValue = VariableValueTxt.Text;
                    SessionStore         csSession     = SessionManager.GetSession();
                    CSLabel              csobj         = csSession.GetCurrentLabel();
                    CodeSoftDTO.Variable variable      = csobj.CSVariables.Where(v => v.Name == variableName).First();
                    variable.Value = variableValue;

                    if (selectedIndex >= VariablesLB.Items.Count - 1)
                    {
                        selectedIndex = -1;
                    }

                    VariablesLB.SelectedIndex = selectedIndex + 1;
                    VariableValueTxt.Text     = "";
                    VariableValueTxt.Focus();
                }
                SaveAndLoad();
            }
            catch (UserError ex)
            {
                MessageLbl.Text = "Save error: " + ex.Message;
            }
            catch (Exception ex)
            {
                SessionManager.ClearSession();
                log4net.LogManager.GetLogger("ERROR").Error(ex);
                Response.Redirect("./");
            }
        }
        protected void PrintBtn_Click(object sender, EventArgs e)
        {
            try
            {
                SaveNoLoading();
                string printer  = string.Empty;
                Int32  quantity = int.Parse(PrintQuantity.Text);
                if (PrintersLB.SelectedItem == null)
                {
                    PrintMessageLbl.Text = "Select a printer!";
                    LoadVariables();
                    LoadPreView();
                    return;
                }
                if (TemplatesLB.SelectedItem == null)
                {
                    PrintMessageLbl.Text = "Select a label!";
                    LoadPreView();
                    LoadLabelInfo();
                    return;
                }
                if (PrintersLB.SelectedItem != null)
                {
                    printer = PrintersLB.SelectedValue;
                }
                SessionStore csSession = SessionManager.GetSession();

                //Do validations.

                Validation.CheckNumberRange(csSession.GetCurrentLabel().CSVariables);

                //End validation.
                if (!PersistVariableValuesChk.Checked)
                {
                    SessionManager.PrintLabel(printer, csSession.GetCurrentLabel(), quantity);
                    csSession.SetVariables(new List <CodeSoftDTO.Variable>());
                    //csSession.SetLabel(null);
                    PrintMessageLbl.Text = "Sent to printer!";
                    //TemplatesLB.SelectedIndex = -1;
                    //PrintersLB.SelectedIndex = -1;
                    PrintQuantity.Text    = "1";
                    VariableValueTxt.Text = "";
                    VariableValueTxt.Focus();
                    LoadVariables();
                }
                else
                {
                    SessionManager.PrintLabel(printer, csSession.GetCurrentLabel(), quantity);
                    PrintMessageLbl.Text  = "Sent to printer!";
                    PrintQuantity.Text    = "1";
                    VariableValueTxt.Text = "";
                    VariableValueTxt.Focus();
                    SaveAndLoad();
                }
            }
            catch (UserError ex)
            {
                PrintMessageLbl.Text = "<b>Input Error!</b><br /> " + ex.Message;
                SaveAndLoad();
            }
            catch (Exception ex)
            {
                SessionManager.ClearSession();
                log4net.LogManager.GetLogger("ERROR").Error(ex);
                PrintMessageLbl.Text = "<span style=\"color:red;\" ><b>Print Failed!</b><br /> " + ex.Message + "</span>";
            }
        }