/// <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 navigation using the supplied properties when called upon the build the control /// </summary> protected override void CreateChildControls() { // append standard class name this.CssClass = (this.CssClass + " alphabet").Trim(); // Add header template if (HeaderTemplate != null) { var header = new XhtmlContainer(); HeaderTemplate.InstantiateIn(header); this.Controls.Add(header); } // only add numerical link if option set if (this.Numbers) { var link = new HtmlAnchor(); link.HRef = BuildLetterPageUrl("0"); link.Title = this.LinkTitle.Trim() + " beginning with 0-9"; link.InnerText = "0—9"; this.Controls.Add(link); } // get list of chars to skip completely int skipCount = String.IsNullOrEmpty(this.SkipChars) ? 0 : this.SkipChars.Length; var charsToSkip = new List <string>(skipCount); for (short i = 0; i < skipCount; i++) { charsToSkip.Add(this.SkipChars.Substring(i, 1).ToLowerInvariant()); } // get list of characters to group together List <string> charsToMerge = new List <string>(this.mergeChars.Length); for (short i = 0; i < this.mergeChars.Length; i++) { var character = this.mergeChars.Substring(i, 1).ToLowerInvariant(); if (!charsToSkip.Contains(character)) { charsToMerge.Add(character); } } // get list of chars to show as disabled int disableCount = String.IsNullOrEmpty(this.DisableChars) ? 0 : this.DisableChars.Length; List <string> charsToDisable = new List <string>(disableCount); for (short i = 0; i < disableCount; i++) { var character = this.DisableChars.Substring(i, 1).ToLowerInvariant(); if (!charsToSkip.Contains(character)) { charsToDisable.Add(character); } } // get list of chars to add classes to int styleCount = String.IsNullOrEmpty(this.StyleChars) ? 0 : this.StyleChars.Length; List <string> charsToStyle = new List <string>(styleCount); for (short i = 0; i < styleCount; i++) { var character = this.StyleChars.Substring(i, 1).ToLowerInvariant(); if (!charsToSkip.Contains(character)) { charsToStyle.Add(character); } } // Add a link for each letter of the Latin alphabet List <string> alphabet = new List <string>(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }); foreach (var character in charsToSkip) { alphabet.Remove(character); } for (int i = 0; i < alphabet.Count; i++) { // If we've just added an item and are about to add another, add a divider if (i > 0 && this.ItemSeparator.Length > 0) { this.Controls.Add(new LiteralControl(this.ItemSeparator)); } // Group character with subsequent characters if specified string letter = alphabet[i]; int charPos; string nextChar; string groups = this.mergeChars.ToLower(); while ((i + 1) < alphabet.Count && charsToMerge.Contains(alphabet[i]) && charsToMerge.Contains(alphabet[i + 1])) { i++; letter = String.Format(CultureInfo.CurrentCulture, "{0}{1}", letter, alphabet[i]); // use a semi-colon to break groups charPos = groups.IndexOf(alphabet[i]) + 1; if (groups.Length > (charPos)) { nextChar = groups.Substring(charPos, 1); if (nextChar == ";") { break; } } } // If any one of the current group of characters is the selected character // display it without a link string upperLetter = letter.ToUpper(CultureInfo.CurrentCulture); if (this.selectedChar.Length > 0 && letter.IndexOf(this.selectedChar) > -1) { HtmlGenericControl span = new HtmlGenericControl("em"); if (charsToStyle.Contains(letter)) { span.Attributes["class"] = letter; } span.InnerText = upperLetter; this.Controls.Add(span); } else { // Grammar - turn "ABC" into "A, B or C" string begin = upperLetter; if (begin.Length > 1) { string[] beginBits = new string[begin.Length]; for (short j = 0; j < begin.Length; j++) { beginBits[j] = begin.Substring(j, 1); if (j > 0 && j < (begin.Length - 1)) { beginBits[j] = ", " + beginBits[j]; } else if (j == (begin.Length - 1)) { beginBits[j] = " or " + beginBits[j]; } } begin = String.Join("", beginBits); } // Is this character or range of characters disabled? bool disabled = true; for (short j = 0; j < letter.Length; j++) { string thisLetter = letter.Substring(j, 1); if (!charsToDisable.Contains(thisLetter)) { disabled = false; break; } } if (disabled) { // Display character(s) as deleted HtmlGenericControl del = new HtmlGenericControl("del"); if (charsToStyle.Contains(letter)) { del.Attributes["class"] = letter; } del.Attributes["title"] = this.disabledTitle + " beginning with " + begin; del.InnerText = upperLetter; this.Controls.Add(del); } else { // Display character(s) as a link HtmlAnchor link = new HtmlAnchor(); if (charsToStyle.Contains(letter)) { link.Attributes["class"] = letter; } link.HRef = BuildLetterPageUrl(letter); link.Title = this.linkTitle + " beginning with " + begin; link.InnerText = upperLetter; this.Controls.Add(link); } } } // Add footer template if (FooterTemplate != null) { XhtmlContainer footer = new XhtmlContainer(); FooterTemplate.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); } } }
/// <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); } } }
/// <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("-", "–"); } // 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; } } }