Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3226938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:30:57+00:00 2026-05-17T16:30:57+00:00

I have a form where users can subscribe and unsubcribe to my email list.

  • 0

I have a form where users can subscribe and unsubcribe to my email list. so far, i have the subscribe button working fine “add member” function. Now i need help with my “delete member ” function (unsubscribe button). it will allows the user to delete their record from the database. When I run the code and click the “unsubscribe” button, i can’t get the logic correct so that it will delete the user’s record if it exisit. thanks for your help!

here’s the code i’m using for the subscribe and unsubscribe buttons ———–

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    public partial class joinmailinglist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void addMember(object sender, EventArgs e)
        {
            // here you are defining the classes for the database and the linq
            mailinglistClassDataContext Class = new mailinglistClassDataContext();
            mailinglistMember member = new mailinglistMember();

            // Now we are going to add the data to the member
           // Here we are going to let the system define a GUID for the unique user ID
            member.memberID = new Guid();

            // here we are going to capture the user inputs and we are going to set these to lower case especially the email so that we can do a proper comparison later.
            member.fname = txtFirstName.Text;
            member.lname = txtLastName.Text;
            member.email = txtEmail.Text;

            // Here we are going to create the URL so we can later remove the user if they decide to opt out. 
            member.removeurl = "http://removeuser.aspx?code=" + member.memberID.ToString();

            // Here we are going to use a LINQ query to search the class of mailinglistmembers for any emails that contain equal values of the text field and select it.
            var duplicatecheck = from emails in Class.mailinglistMembers
                                 where emails.email.Contains(txtEmail.Text)
                                 select emails;

            // Here we are going to check that the count of duplicate is equal to zero. If so then we are going to insert the member information into the class and then submit the changes to the database.
            if (duplicatecheck.Count() == 0)
            {
                Class.mailinglistMembers.InsertOnSubmit(member);
                Class.SubmitChanges();

            }
            else
            {
                lblDuplicate.Text = "Hey you have already entered your information.";
            }
        }


 protected void deleteMember(object sender, EventArgs e)
    {



        // here you are defining the classes for the database and the linq
        mailingListClassDataContext Class = new mailingListClassDataContext();
        mailinglistMember member = new mailinglistMember();



        // here we are going to capture the user inputs and we are going to set these to lower case especially the email so that we can do a proper comparison later.

        member.email = txtEmail.Text;


        // Here we are going to use a LINQ query to search the class of mailinglistmembers for any emails that contain equal values of the text field and select it.

                        var deleterec = from emails in Class.mailinglistMembers
                        where emails.email.Contains(txtEmail.Text) 
                             select emails;

        // Here we check if the record exisits

        if (deleterec.Count() == 0)
        {
            Class.mailinglistMembers.DeleteOnSubmit(member);
            Class.SubmitChanges();
            Response.Redirect("frm_confirmation.aspx");

        }
        else
        {
            lblDelete.Text = "No record exsists!";
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:30:58+00:00Added an answer on May 17, 2026 at 4:30 pm

    Try the below code.

    string mailAddress = txtEmail.Text.Trim().ToLower();
    
    using (var db = new mailingListClassDataContext())
    {
        var records = from e in db.mailinglistMembers
                      where e.mail == mailAddress
                      select e;
    
        if (records != null)
        {
            db.mailinglistMembers.DeleteAllOnSubmit(records);
            db.SubmitChanges();
            Response.Redirect("frm_confirmation.aspx");
            Response.End();
        }
        else
        {
            lblDelete.Text = "No records exists!";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form in witch users can add their working hours view them
I have a form which users can add controls to and when they right
I have a form where users can add input fields with jQuery. <input type="text"
I have a dynamic form that users can add/delete sets of input fields. I
I have a very simple form where users can enter their email and click
I have a form where users can modify a collection of objects using a
I have a form where users can enter the names and emails addresses of
Let's say I have a form where users can search for people whose name
I have a form where my users can register to my site. They fill
I have a form in my django app where users can upload files. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.