Exemple #1
0
    protected void InitNewsletterSelector()
    {
        // Show/hide newsletter list
        plcNwsList.Visible = NewsletterName.EqualsCSafe("nwsletuserchoose", true);

        if (plcNwsList.Visible)
        {
            chooseMode = true;

            if ((!ExternalUse || !RequestHelper.IsPostBack()) && (chklNewsletters.Items.Count == 0))
            {
                DataSet ds = null;

                // Try to get data from cache
                using (var cs = new CachedSection <DataSet>(ref ds, CacheMinutes, true, CacheItemName, "newslettersubscription", SiteContext.CurrentSiteName))
                {
                    if (cs.LoadData)
                    {
                        // Get the data
                        ds = NewsletterInfoProvider.GetNewslettersForSite(SiteContext.CurrentSiteID).OrderBy("NewsletterDisplayName").Columns("NewsletterDisplayName", "NewsletterName");

                        // Add data to the cache
                        if (cs.Cached)
                        {
                            // Prepare cache dependency
                            cs.CacheDependency = CacheHelper.GetCacheDependency("newsletter.newsletter|all");
                        }

                        cs.Data = ds;
                    }
                }

                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    ListItem li          = null;
                    string   displayName = null;

                    // Fill checkbox list with newsletters
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        // Get localized string
                        displayName = ResHelper.LocalizeString(ValidationHelper.GetString(dr["NewsletterDisplayName"], string.Empty));

                        li = new ListItem(HTMLHelper.HTMLEncode(displayName), ValidationHelper.GetString(dr["NewsletterName"], string.Empty));
                        chklNewsletters.Items.Add(li);
                    }
                }
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
        }
        else
        {
            // Hide info label of the captcha control because the newsletter subscription web part has its own
            scCaptcha.ShowInfoLabel = false;

            lblFirstName.Text         = FirstNameText;
            lblLastName.Text          = LastNameText;
            lblEmail.Text             = EmailText;
            lblCaptcha.ResourceString = CaptchaText;
            plcCaptcha.Visible        = DisplayCaptcha;

            if ((UseImageButton) && (!String.IsNullOrEmpty(ImageButtonURL)))
            {
                pnlButtonSubmit.Visible = false;
                pnlImageSubmit.Visible  = true;
                btnImageSubmit.ImageUrl = ImageButtonURL;
            }
            else
            {
                pnlButtonSubmit.Visible = true;
                pnlImageSubmit.Visible  = false;
                btnSubmit.Text          = ButtonText;
            }

            // Display labels only if user is logged in and property AllowUserSubscribers is set to true
            if (AllowUserSubscribers && AuthenticationHelper.IsAuthenticated())
            {
                visibleFirstName = false;
                visibleLastName  = false;
                visibleEmail     = false;
            }
            // Otherwise display text-boxes
            else
            {
                visibleFirstName = true;
                visibleLastName  = true;
                visibleEmail     = true;
            }

            // Hide first name field if not required
            if (!DisplayFirstName)
            {
                visibleFirstName = false;
            }
            // Hide last name field if not required
            if (!DisplayLastName)
            {
                visibleLastName = false;
            }

            // Show/hide newsletter list
            plcNwsList.Visible = NewsletterName.EqualsCSafe("nwsletuserchoose", true);
            if (plcNwsList.Visible)
            {
                chooseMode = true;

                if ((!ExternalUse || !RequestHelper.IsPostBack()) && (chklNewsletters.Items.Count == 0))
                {
                    DataSet ds = null;

                    // Try to get data from cache
                    using (var cs = new CachedSection <DataSet>(ref ds, CacheMinutes, true, CacheItemName, "newslettersubscription", SiteContext.CurrentSiteName))
                    {
                        if (cs.LoadData)
                        {
                            // Get the data
                            ds = NewsletterInfoProvider.GetNewslettersForSite(SiteContext.CurrentSiteID).OrderBy("NewsletterDisplayName").Columns("NewsletterDisplayName", "NewsletterName");

                            // Add data to the cache
                            if (cs.Cached)
                            {
                                // Prepare cache dependency
                                cs.CacheDependency = CacheHelper.GetCacheDependency("newsletter.newsletter|all");
                            }

                            cs.Data = ds;
                        }
                    }

                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        ListItem li          = null;
                        string   displayName = null;

                        // Fill checkbox list with newsletters
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            displayName = ResHelper.LocalizeString(ValidationHelper.GetString(dr["NewsletterDisplayName"], string.Empty));

                            li = new ListItem(HTMLHelper.HTMLEncode(displayName), ValidationHelper.GetString(dr["NewsletterName"], string.Empty));
                            chklNewsletters.Items.Add(li);
                        }
                    }
                }
            }

            // Set SkinID properties
            if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (string.IsNullOrEmpty(ValidationHelper.GetString(Page.StyleSheetTheme, string.Empty))))
            {
                string skinId = SkinID;
                if (!string.IsNullOrEmpty(skinId))
                {
                    lblFirstName.SkinID = skinId;
                    lblLastName.SkinID  = skinId;
                    lblEmail.SkinID     = skinId;
                    txtFirstName.SkinID = skinId;
                    txtLastName.SkinID  = skinId;
                    txtEmail.SkinID     = skinId;
                    btnSubmit.SkinID    = skinId;
                }
            }
        }
    }