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

Forums / Developing with Sitefinity / unsubscribe Newsletter Null ReferenceException

unsubscribe Newsletter Null ReferenceException

4 posts, 0 answered
  1. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    28 Apr 2010
    Link to this post
    Hi

    we are using a customized Newsletter-Class which generats an EMail with an unsubscrib Hyperlink. As Querystring i add the email-id and group-id from the newsletter. So in case the user A calls the unsubscribe link, i got the necessary data to delete user A. This is the code i use:
            if (oSubscriber != null)
            {
                Guid oGroupID = new Guid(sGruppenID);
                oNLManager.DeleteGroupSubscriberRelation(oGroupID, oSubscriber.SubscriberId);            
                oNLManager.DeleteSubscriber(oSubscriber);           
            }

    Now user A has removed from the correct NewsletterGroup but if i want to edit (Backend) the subscribers of another newsletter in which user  A was not included. Then i get an Null Reference Exception, so i guess  there is a damage in the database. Do you have any idea what went wrong?

    [NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]
       Telerik.Notifications.Newsletters.WebControl.SubscriberList.Grid_RowDataBound(Object sender, GridViewRowEventArgs e) +304
       System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +108
       System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
       System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       System.Web.UI.WebControls.GridView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.WebControls.GridView.get_Rows() +34
       Telerik.Notifications.Newsletters.WebControl.SubscribersBase.OnPreRender(EventArgs e) +205
       System.Web.UI.Control.PreRenderRecursiveInternal() +80
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    


    Regards David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Apr 2010
    Link to this post
    Hello DPC David,

    Check whether you have the following template in your website Sitefinity\Admin\ControlTemplates\Notifications\SubscribersTemplate.ascx and controls with the IDs shown below

    • editbtn
    • lblusername
    • profilebtn
    • EditSubscriber
    The error could be thrown if you have

    subscriber withouth

    • email
    • last name
    • first name

    or Subscriber.SubscriberId is null - there is no such subscriber.

    Try to get the subscribers for the group you are trying to see by using

    IList subscribers = (IList)this.newsletterManager.GetSubscribersOfGroup(this.selectedGroupId, string.Empty) and see whether  there are some records that should have been deleted.

    The correct code to unsubscribe a user is shown below

    var dataManager = new DataManager ( );
     
    IList gSubs = dataManager.GetSubscriberGroupsOfSubscriber ( subscriberEmail );
    foreach ( IGroupSubscriber gSub in gSubs )
    {
        dataManager.DeleteGroupSubscriberRelation ( gSub );
    }
     
    ISubscriber subscriber = dataManager.GetSubscriber ( subscriberEmail );
    if ( subscriber != null )
        dataManager.DeleteSubscriber ( subscriber );

    You are deleting the subscriber, but not all relations and it could exist in another group. When the Grid is bound this subscriber cannot be found because it has been removed, but it is still associated with an group and you get the null error.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    29 Apr 2010
    Link to this post
    Hi

    1. Sitefinity\Admin\ControlTemplates\Notifications\SubscribersTemplate.ascx 
    I could not find the ID EditSubscriber in this Template. I Checked even my test Installation (3.7) in which i had made no changes in the Code. In case it is realy missing in my Project, could you attach this File?

    2. The error could be thrown if you have subscriber withouth email, last name, first name
    If First Name and Last Name are required Field Values then they should be marked as required in the Backend and saving without should not be possible?

    3. You are deleting the subscriber, but not all relations and it could exist in another group. When the Grid is bound this subscriber cannot be found because it has been removed, but it is still associated with an group and you get the null error.
    Hmm that was with purpose. I wanted User A to remove only from one Group Demo and keep him in Group Weekly_Newsletter. That is the reason why i tried to delete only the relation to Group Demo.
    Is that not possible? I hope i got you right and thanks for the support

    Regards David
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    30 Apr 2010
    Link to this post
    Hello DPC David,

    To unsubscribe an user for a group you only have to delete the group relation.

    ISubscriber subscriber = this.newsletterManager.GetSubscriber(subscribersIds[i]);
    if (subscriber != null)
    {
        if (subscriber.Groups.Count <= 1)                this.newsletterManager.DeleteGroupSubscriberRelation(this.SelectedGroupId, subscriber.SubscriberId);
    }

    It looks like you have deleted the user and the relation to a give group has been left.

    You could check the data in your database tables

    [sf_Notif_Subscriber] -ID and data of a subscriber

    [sf_Notif_Group] - ID of groups

    [sf_Notif_GroupSubscriber] - relation between group and subscriber.

    EditSubscriber - should not be in the Sitefinity\Admin\ControlTemplates\Notifications\SubscribersTemplate.ascx

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered