protected void btnDelete_Click(object sender, EventArgs e)
    {
        contact_id = Convert.ToInt32(Request.QueryString["contactID"]);
        qCom_Contact contact = new qCom_Contact(contact_id);
        contact.Available = "No";
        contact.MarkAsDelete = 1;
        contact.OKEmail = "No";
        contact.Update();

        if (Request.QueryString["edit-mode"] == "in-place")
            Response.Redirect(Request.QueryString["returnURL"]);
        else
            Response.Redirect("contacts-list.aspx");
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {
            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            if (!String.IsNullOrEmpty(Request.QueryString["contactID"]))
            {
                contact_id = Convert.ToInt32(Request.QueryString["contactID"]);
                qCom_Contact contact = new qCom_Contact(contact_id);
                contact.FirstName = txtFirstName.Text;
                contact.LastName = txtLastName.Text;
                contact.Email = txtEmail.Text;
                contact.Keywords = txtKeywords.Text;
                contact.Source = txtSource.Text;
                contact.MainGroup = Convert.ToInt32(txtMainGroup.Text);
                contact.SubGroup = Convert.ToInt32(txtSubGroup.Text);
                contact.DID = txtDID.Text;
                contact.Partner = txtPartner.Text;
                contact.CustomHTMLElement = txtCustomHTMLElement.Text;

                if (!String.IsNullOrEmpty(Convert.ToString(rdtUnsubscribed.SelectedDate)))
                    contact.Unsubscribed = Convert.ToDateTime(rdtUnsubscribed.SelectedDate);
                if (!String.IsNullOrEmpty(Convert.ToString(rdtReportedAsSpam.SelectedDate)))
                    contact.ReportedAsSpam = Convert.ToDateTime(rdtReportedAsSpam.SelectedDate);
                if (!String.IsNullOrEmpty(Convert.ToString(ddlCampaigns.SelectedValue)))
                    contact.UnsubscribedCampaignID = Convert.ToInt32(ddlCampaigns.SelectedValue);
                if (!String.IsNullOrEmpty(Convert.ToString(ddlCampaignsSPAM.SelectedValue)))
                    contact.ReportedAsSpamCampaignID = Convert.ToInt32(ddlCampaignsSPAM.SelectedValue);

                contact.OKEmail = rblOkEmail.SelectedValue;
                contact.Available = rblAvailable.SelectedValue;
                contact.Update();
            }
            else
            {
                qCom_Contact contact = new qCom_Contact();
                contact.FirstName = txtFirstName.Text;
                contact.LastName = txtLastName.Text;
                contact.Email = txtEmail.Text;
                contact.Keywords = txtKeywords.Text;
                contact.Source = txtSource.Text;
                contact.MainGroup = Convert.ToInt32(txtMainGroup.Text);
                contact.SubGroup = Convert.ToInt32(txtSubGroup.Text);
                contact.DID = txtDID.Text;
                contact.Partner = txtPartner.Text;
                contact.CustomHTMLElement = txtCustomHTMLElement.Text;

                if (!String.IsNullOrEmpty(Convert.ToString(rdtUnsubscribed.SelectedDate)))
                    contact.Unsubscribed = Convert.ToDateTime(rdtUnsubscribed.SelectedDate);
                if (!String.IsNullOrEmpty(Convert.ToString(rdtReportedAsSpam.SelectedDate)))
                    contact.ReportedAsSpam = Convert.ToDateTime(rdtReportedAsSpam.SelectedDate);
                if (!String.IsNullOrEmpty(Convert.ToString(ddlCampaigns.SelectedValue)))
                    contact.UnsubscribedCampaignID = Convert.ToInt32(ddlCampaigns.SelectedValue);
                if (!String.IsNullOrEmpty(Convert.ToString(ddlCampaignsSPAM.SelectedValue)))
                    contact.ReportedAsSpamCampaignID = Convert.ToInt32(ddlCampaignsSPAM.SelectedValue);

                contact.OKEmail = rblOkEmail.SelectedValue;
                contact.Available = rblAvailable.SelectedValue;
                contact.Insert();

                contact_id = contact.ContactID;
            }

            if (!String.IsNullOrEmpty(Request.QueryString["contactID"]))
            {
                lblMessage.Text = "*** Record Successfully Updated ***";
                lblMessageBottom.Text = "*** Record Successfully Updated ***";
                if (Request.QueryString["edit-mode"] == "in-place")
                    Response.Redirect(Request.QueryString["returnURL"]);
                else
                    Response.Redirect("contacts-list.aspx");
            }
            else
            {
                Response.Redirect(Request.Url.ToString() + "?mode=add-successful&contactID=" + contact_id);
            }
        }
    }