Custom Unsubscribe form widget

Posted by Community Admin on 04-Aug-2018 22:25

Custom Unsubscribe form widget

All Replies

Posted by Community Admin on 15-Dec-2011 00:00

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

Posted by Community Admin on 20-Dec-2011 00:00

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

This thread is closed