1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Unsubscribe form widget

Custom Unsubscribe form widget

2 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    15 Dec 2011
    Link to this post
    When a user Unsubscribes, we want them to be removed from ALL mailing lists.  To do this, do I need to create a custom unsubscribe form widget?  
    Sitefinity 4.2
  2. Boyko Karadzhov
    Boyko Karadzhov avatar
    56 posts
    Registered:
    05 Dec 2016
    20 Dec 2011
    Link to this post
    Hi Laura,

     Yes, the Unsubscribe Form control works with just one mailing list. To be able to unsubscribe from all mailing lists you may inherit it. Your new control should be something like this:

    public class CustomUnsubscribe : UnsubscribeForm
    {
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        {
            base.InitializeControls(container);
     
            this.UnsubscribeButton.Click -= this.UnsubscribeButton_Click;
            this.UnsubscribeButton.Click += this.UnsubscribeButtonCustom_Click;
        }
     
        protected void UnsubscribeButtonCustom_Click(object sender, EventArgs e)
        {
            this.RemoveSubscriber();
        }
     
        private void RemoveSubscriber()
        {
            var newslettersManager = NewslettersManager.GetManager(this.ProviderName);
            var email = this.EmailAddress.Text.ToLower();
            var subscriber = newslettersManager.GetSubscribers().Where(s => s.Email == email).SingleOrDefault();
            if (subscriber != null)
            {
                var mailLists = newslettersManager.GetMailingLists().Where(m => m.Subscribers.Contains(subscriber));
                foreach (var mailList in mailLists)
                {
                    newslettersManager.Unsubscribe(subscriber, mailList.Id);
                }
                newslettersManager.SaveChanges();
            }
        }
    }
    Best wishes,
    Boyko Karadzhov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered