/// <summary>
        /// Clears the current page display and replaces it with an xhtml message.
        /// </summary>
        private void ShowConfirmationMessage(string confirmationXHtml)
        {
            this.EnsureChildControls();
            this.Controls.Clear();

            // Add header template
            if (ConfirmationHeaderTemplate != null)
            {
                XhtmlContainer header = new XhtmlContainer();
                ConfirmationHeaderTemplate.InstantiateIn(header);
                this.Controls.Add(header);
            }

            // Add content template
            if (ConfirmationTemplate == null)
            {
                ConfirmationTemplate = new DefaultTemplate(this.Service, confirmationXHtml);
            }

            XhtmlContainer confirmation = new XhtmlContainer();

            ConfirmationTemplate.InstantiateIn(confirmation);
            this.Controls.Add(confirmation);

            // If the confirmation contains a Literal with the id "serviceName", replace it with the current service name
            Literal serviceName = confirmation.FindControl("ConfirmationServiceName") as Literal;

            if (serviceName != null)
            {
                serviceName.Text = Service.Name;
            }

            // Add footer template
            if (ConfirmationFooterTemplate != null)
            {
                XhtmlContainer footer = new XhtmlContainer();
                ConfirmationFooterTemplate.InstantiateIn(footer);
                this.Controls.Add(footer);
            }
        }
        /// <summary>
        /// Display a message indicating that activation has failed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisplayMessage_DeactivationFailed(object sender, EventArgs e)
        {
            this.EnsureChildControls();
            this.Controls.Clear();

            if (FailureTemplate == null)
            {
                FailureTemplate = new DefaultTemplate(this.Service, Resources.EmailDeactivationFailure);
            }

            XhtmlContainer container = new XhtmlContainer();

            FailureTemplate.InstantiateIn(container);
            this.Controls.Add(container);

            // If the template contains a Literal with the id "FailureServiceName", replace it with the current service name
            Literal serviceName = container.FindControl("FailureServiceName") as Literal;

            if (serviceName != null)
            {
                serviceName.Text = Service.Name;
            }
        }
        /// <summary>
        /// Display a message indicating that activation has failed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisplayMessage_ActivationFailed(object sender, EventArgs e)
        {
            this.EnsureChildControls();
            this.Controls.Clear();

            if (FailureTemplate == null) FailureTemplate = new DefaultTemplate(this.Service, Resources.EmailActivationFailure);

            XhtmlContainer container = new XhtmlContainer();
            FailureTemplate.InstantiateIn(container);
            this.Controls.Add(container);

            // If the intro contains a Literal with the id "FailureServiceName", replace it with the current service name
            Literal serviceName = container.FindControl("FailureServiceName") as Literal;
            if (serviceName != null) serviceName.Text = Service.Name;
        }
        /// <summary>
        /// Build the email address entry form
        /// </summary>
        protected override void CreateChildControls()
        {
            if (this.Service == null || this.Service.Id <= 0 || String.IsNullOrEmpty(this.Service.Name))
            {
                // Add header template
                if (NotFoundHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    NotFoundHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add no service template
                if (NotFoundTemplate == null)
                {
                    NotFoundTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeNoService);
                }

                XhtmlContainer template = new XhtmlContainer();
                NotFoundTemplate.InstantiateIn(template);
                this.Controls.Add(template);

                // Add footer template
                if (NotFoundFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    NotFoundFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
            else
            {
                bool IsNewSubscription = true;

                // Get activation code from querystring
                string subscriptionCode = this.Context.Request.QueryString[this.CodeParameter];
                // Did we find a valid subscription code?
                if (!string.IsNullOrEmpty(subscriptionCode))
                {
                    // This is a change of an existing subscription.
                    IsNewSubscription = false;
                }

                // Add header template
                if (SubscribeHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    SubscribeHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add intro template
                if (IntroTemplate == null)
                {
                    if (IsNewSubscription)
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeIntro);
                    }
                    else
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.SubscriptionOptionsUpdateIntro);
                    }
                }

                XhtmlContainer intro = new XhtmlContainer();
                IntroTemplate.InstantiateIn(intro);
                this.Controls.Add(intro);

                // If the intro contains a Literal with the id "serviceName", replace it with the current service name
                Literal serviceName = intro.FindControl("IntroServiceName") as Literal;
                if (serviceName != null)
                {
                    serviceName.Text = Service.Name;
                }

                // validation messages - added in at this point to work around a .NET bug
                this.Controls.Add(new EsccValidationSummary());

                // Add form header template
                if (FormHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    FormHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                if (IsNewSubscription)
                {
                    // Display controls suitable for a new subscription.

                    // email box
                    this.email           = new TextBox();
                    this.email.MaxLength = 255;    // e-GIF
                    this.email.ID        = "sub1"; // don't call the box "email", spammers look for that
                    this.email.CssClass  = "email";

                    FormPart emailPart = new FormPart(Resources.EmailEntryPrompt, this.email);
                    emailPart.Required = true;
                    this.Controls.Add(emailPart);

                    // Confirm email box
                    this.confirmEmail           = new TextBox();
                    this.confirmEmail.MaxLength = 255; // e-GIF
                    this.confirmEmail.ID        = "sub2";
                    this.confirmEmail.CssClass  = "email";

                    FormPart confirmPart = new FormPart(Resources.EmailConfirmEntryPrompt, this.confirmEmail);
                    confirmPart.Required = true;
                    this.Controls.Add(confirmPart);

                    // validate email
                    EsccRequiredFieldValidator vrEmail = new EsccRequiredFieldValidator(this.email.ID, Resources.EmailRequiredError);
                    this.Controls.Add(vrEmail);

                    EmailValidator vrxEmail = new EmailValidator(this.email.ID, Resources.EmailInvalidError);
                    this.Controls.Add(vrxEmail);

                    // validate confirmation of email - no need for an EmailValidator because it must match the one above
                    EsccRequiredFieldValidator vrConfirm = new EsccRequiredFieldValidator(this.confirmEmail.ID, Resources.EmailConfirmRequiredError);
                    this.Controls.Add(vrConfirm);

                    EsccCustomValidator vMatchConfirm = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailConfirmMismatchError);
                    vMatchConfirm.ServerValidate += new ServerValidateEventHandler(vMatchConfirm_ServerValidate);
                    this.Controls.Add(vMatchConfirm);

                    // validate that email is not already subscribed to this service
                    EsccCustomValidator vSubscriptionExists = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailAlreadySubscribed);
                    vSubscriptionExists.ServerValidate += new ServerValidateEventHandler(vSubscriptionExists_ServerValidate);
                    this.Controls.Add(vSubscriptionExists);
                }
                else
                {
                    // Display controls suitable for a subscription update.

                    // Add the subscription email address as information feedback.
                    this.emailReadOnly      = new Label();
                    this.emailReadOnly.ID   = "sub3"; // don't call the box "email", spammers look for that
                    this.emailReadOnly.Text = this.GetEmailAddressForExistingSubscription(new Guid(subscriptionCode));

                    FormPart emailPart = new FormPart(Properties.Resources.EmailEntryPrompt, this.emailReadOnly);
                    this.Controls.Add(emailPart);
                }

                // Add extra options template
                if (FormExtraOptionsTemplate != null)
                {
                    XhtmlContainer extraOptions = new XhtmlContainer();
                    FormExtraOptionsTemplate.InstantiateIn(extraOptions);
                    this.Controls.Add(extraOptions);
                }

                // Add form footer template
                if (FormFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    FormFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }

                // Submit button
                EsccButton submitButton = new EsccButton();
                submitButton.Text     = Resources.SubscribeButtonText;
                submitButton.CssClass = "button";
                submitButton.Click   += new EventHandler(submitButton_Click);

                // Update button
                EsccButton updateButton = new EsccButton();
                updateButton.Text     = Resources.SubscriptionOptionsUpdateButtonText;
                updateButton.CssClass = "button buttonBigger";
                updateButton.Click   += new EventHandler(updateButton_Click);

                FormButtons buttons = new FormButtons();
                if (IsNewSubscription)
                {
                    buttons.Controls.Add(submitButton);
                }
                else
                {
                    buttons.Controls.Add(updateButton);
                }
                this.Controls.Add(buttons);

                // Add footer template
                if (SubscribeFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    SubscribeFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
        }
        /// <summary>
        /// Clears the current page display and replaces it with an xhtml message.
        /// </summary>
        private void ShowConfirmationMessage(string confirmationXHtml)
        {
            this.EnsureChildControls();
            this.Controls.Clear();

            // Add header template
            if (ConfirmationHeaderTemplate != null)
            {
                XhtmlContainer header = new XhtmlContainer();
                ConfirmationHeaderTemplate.InstantiateIn(header);
                this.Controls.Add(header);
            }

            // Add content template
            if (ConfirmationTemplate == null) ConfirmationTemplate = new DefaultTemplate(this.Service, confirmationXHtml);

            XhtmlContainer confirmation = new XhtmlContainer();
            ConfirmationTemplate.InstantiateIn(confirmation);
            this.Controls.Add(confirmation);

            // If the confirmation contains a Literal with the id "serviceName", replace it with the current service name
            Literal serviceName = confirmation.FindControl("ConfirmationServiceName") as Literal;
            if (serviceName != null) serviceName.Text = Service.Name;

            // Add footer template
            if (ConfirmationFooterTemplate != null)
            {
                XhtmlContainer footer = new XhtmlContainer();
                ConfirmationFooterTemplate.InstantiateIn(footer);
                this.Controls.Add(footer);
            }
        }
        /// <summary>
        /// Build the email address entry form
        /// </summary>
        protected override void CreateChildControls()
        {
            if (this.Service == null || this.Service.Id <= 0 || String.IsNullOrEmpty(this.Service.Name))
            {
                // Add header template
                if (NotFoundHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    NotFoundHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add no service template
                if (NotFoundTemplate == null) NotFoundTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeNoService);

                XhtmlContainer template = new XhtmlContainer();
                NotFoundTemplate.InstantiateIn(template);
                this.Controls.Add(template);

                // Add footer template
                if (NotFoundFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    NotFoundFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
            else
            {
                bool IsNewSubscription = true;

                // Get activation code from querystring
                string subscriptionCode = this.Context.Request.QueryString[this.CodeParameter];
                // Did we find a valid subscription code?
                if (!string.IsNullOrEmpty(subscriptionCode))
                {
                    // This is a change of an existing subscription.
                    IsNewSubscription = false;
                }

                // Add header template
                if (SubscribeHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    SubscribeHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add intro template
                if (IntroTemplate == null)
                {
                    if (IsNewSubscription)
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeIntro);
                    }
                    else
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.SubscriptionOptionsUpdateIntro);
                    }
                }

                XhtmlContainer intro = new XhtmlContainer();
                IntroTemplate.InstantiateIn(intro);
                this.Controls.Add(intro);

                // If the intro contains a Literal with the id "serviceName", replace it with the current service name
                Literal serviceName = intro.FindControl("IntroServiceName") as Literal;
                if (serviceName != null) serviceName.Text = Service.Name;

                // validation messages - added in at this point to work around a .NET bug
                this.Controls.Add(new EsccValidationSummary());

                // Add form header template
                if (FormHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    FormHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                if (IsNewSubscription)
                {
                    // Display controls suitable for a new subscription.

                    // email box
                    this.email = new TextBox();
                    this.email.MaxLength = 255; // e-GIF
                    this.email.ID = "sub1"; // don't call the box "email", spammers look for that
                    this.email.CssClass = "email";

                    FormPart emailPart = new FormPart(Resources.EmailEntryPrompt, this.email);
                    emailPart.Required = true;
                    this.Controls.Add(emailPart);

                    // Confirm email box
                    this.confirmEmail = new TextBox();
                    this.confirmEmail.MaxLength = 255; // e-GIF
                    this.confirmEmail.ID = "sub2";
                    this.confirmEmail.CssClass = "email";

                    FormPart confirmPart = new FormPart(Resources.EmailConfirmEntryPrompt, this.confirmEmail);
                    confirmPart.Required = true;
                    this.Controls.Add(confirmPart);

                    // validate email
                    EsccRequiredFieldValidator vrEmail = new EsccRequiredFieldValidator(this.email.ID, Resources.EmailRequiredError);
                    this.Controls.Add(vrEmail);

                    EmailValidator vrxEmail = new EmailValidator(this.email.ID, Resources.EmailInvalidError);
                    this.Controls.Add(vrxEmail);

                    // validate confirmation of email - no need for an EmailValidator because it must match the one above
                    EsccRequiredFieldValidator vrConfirm = new EsccRequiredFieldValidator(this.confirmEmail.ID, Resources.EmailConfirmRequiredError);
                    this.Controls.Add(vrConfirm);

                    EsccCustomValidator vMatchConfirm = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailConfirmMismatchError);
                    vMatchConfirm.ServerValidate += new ServerValidateEventHandler(vMatchConfirm_ServerValidate);
                    this.Controls.Add(vMatchConfirm);

                    // validate that email is not already subscribed to this service
                    EsccCustomValidator vSubscriptionExists = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailAlreadySubscribed);
                    vSubscriptionExists.ServerValidate += new ServerValidateEventHandler(vSubscriptionExists_ServerValidate);
                    this.Controls.Add(vSubscriptionExists);
                }
                else
                {
                    // Display controls suitable for a subscription update.

                    // Add the subscription email address as information feedback.
                    this.emailReadOnly = new Label();
                    this.emailReadOnly.ID = "sub3"; // don't call the box "email", spammers look for that
                    this.emailReadOnly.Text = this.GetEmailAddressForExistingSubscription(new Guid(subscriptionCode));

                    FormPart emailPart = new FormPart(Properties.Resources.EmailEntryPrompt, this.emailReadOnly);
                    this.Controls.Add(emailPart);
                }

                // Add extra options template
                if (FormExtraOptionsTemplate != null)
                {
                    XhtmlContainer extraOptions = new XhtmlContainer();
                    FormExtraOptionsTemplate.InstantiateIn(extraOptions);
                    this.Controls.Add(extraOptions);
                }

                // Add form footer template
                if (FormFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    FormFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }

                // Submit button
                EsccButton submitButton = new EsccButton();
                submitButton.Text = Resources.SubscribeButtonText;
                submitButton.CssClass = "button";
                submitButton.Click += new EventHandler(submitButton_Click);

                // Update button
                EsccButton updateButton = new EsccButton();
                updateButton.Text = Resources.SubscriptionOptionsUpdateButtonText;
                updateButton.CssClass = "button buttonBigger";
                updateButton.Click += new EventHandler(updateButton_Click);

                FormButtons buttons = new FormButtons();
                if (IsNewSubscription) buttons.Controls.Add(submitButton); else buttons.Controls.Add(updateButton);
                this.Controls.Add(buttons);

                // Add footer template
                if (SubscribeFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    SubscribeFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Notifies server controls that use composition-based implementation to create any child
        /// controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            // Get the paging controller
            if (this.PagingControllerId != null && this.PagingControllerId.Length > 0)
            {
                this.PagingController = this.Parent.FindControl(this.PagingControllerId) as PagingController;

                // this isn't normal behaviour but is needed
                // for backwards compatibility
                if (this.PagingController == null)
                {
                    this.PagingController = this.Page.FindControl(this.PagingControllerId) as PagingController;
                }
            }

            // did we find a paging controller?
            if (this.PagingController == null)
            {
                string badControllerId = PagingControllerId == null ? "<undefined>" : PagingControllerId;

                throw new Exception(
                          string.Format(CultureInfo.CurrentCulture, "No paging controller with specified id '{0}'", badControllerId)
                          );
            }

            // Only display if there are some search results
            if (this.PagingController.TotalResults > 0)
            {
                this.Visible = true;

                if (this.PagingTemplate != null)
                {
                    // Base the display on the template
                    using (var container = new XhtmlContainer())
                    {
                        this.PagingTemplate.InstantiateIn(container);

                        // If range control is found, inject "{first-on-page} to {last-on-page} of {total}", or just "{total}" if it's only one page
                        var range = container.FindControl("range") as Literal;
                        if (range != null)
                        {
                            range.Text = HttpUtility.HtmlEncode(this.PagingController.CurrentRange).Replace("-", "&#8211;");
                        }

                        // If results control is found, inject the results singular or plural text
                        var results = container.FindControl("results") as Literal;
                        if (results != null)
                        {
                            results.Text = HttpUtility.HtmlEncode(this.PagingController.ResultsTextCurrent);
                        }

                        // If pages control is found, inject the list of pages
                        var pages = container.FindControl("pages") as Literal;
                        if (pages != null)
                        {
                            pages.Text = this.BuildPagesXhtml();
                        }

                        this.Controls.Add(container);
                    }
                }
                else
                {
                    // Otherwise create a containing box
                    using (HtmlGenericControl inner1 = new HtmlGenericControl("div"))
                    {
                        using (HtmlGenericControl inner2 = new HtmlGenericControl("div"))
                        {
                            using (HtmlGenericControl inner3 = new HtmlGenericControl("div"))
                            {
                                this.Controls.Add(inner1);
                                inner1.Controls.Add(inner2);
                                inner2.Controls.Add(inner3);

                                // Add "page x of y"
                                using (HtmlGenericControl resultsInContext = new HtmlGenericControl("div"))
                                {
                                    resultsInContext.Attributes["class"] = "pagingResultsInContext";
                                    resultsInContext.InnerHtml           = this.BuildResultsInContextXhtml();
                                    inner3.Controls.Add(resultsInContext);
                                }

                                // Add links to other pages
                                using (HtmlGenericControl pages = new HtmlGenericControl("div"))
                                {
                                    pages.Attributes["class"] = "pagingPages";
                                    pages.InnerHtml           = this.BuildPagesXhtml();
                                    if (pages.InnerHtml.Length > 0)
                                    {
                                        inner3.Controls.Add(pages);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.NoResultsTemplate != null)
                {
                    using (var templateContainer = new XhtmlContainer())
                    {
                        this.NoResultsTemplate.InstantiateIn(templateContainer);
                        this.Controls.Add(templateContainer);
                    }
                }
                else
                {
                    this.Visible = false;
                }
            }
        }