Example #1
0
        /// <summary>
        /// Removes the selected file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeFile_Click(object sender, EventArgs e)
        {
            // Locate the selected file index
            if (sender != null)
            {
                EsccButton removeFile = (EsccButton)sender;

                // Extract the integer index value from the button's string id
                int index = -1;
                try
                {
                    index = Convert.ToInt32(removeFile.ID.Replace("removeFile_", ""));
                }
                catch { };

                // Did we get a successful index value?
                if ((index >= 0) && (index < maxFiles))
                {
                    // Use the index to get the actual file id from the respective hidden control.
                    HtmlInputHidden idBox      = this.fileIdArray[index];
                    int             fileDataId = Convert.ToInt32(idBox.Value);
                    // Get the linked item id from the querystring if it exists
                    int LinkedItemId = 0;
                    try
                    {
                        string paramName = QueryStringParameterNameForLinkedItemID();
                        LinkedItemId = Convert.ToInt32(this.Context.Request.QueryString[paramName]);
                    }
                    catch { }
                    // Delete the file from the database
                    this.DeleteFileInDB(fileDataId, LinkedItemId);
                    // Remove all trace of this file from the file data arrays too.
                    this.RemoveFileDataFromArrays(fileDataId);
                }
                else
                {
                    throw new Exception("Could not identify the file to remove from the button pressed on the page.");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify 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()
        {
            // Place the validation summary control at the top of this control
            this.Controls.Add(this.vUploadSummary);

            // Add the form parts
            this.Controls.Add(this.fileBrowserPart);
            this.Controls.Add(this.placePostFileBrowserParts);
            this.Controls.Add(this.addButtonPart);
            this.Controls.Add(this.fieldsetPart);

            // Best to use the Label control here because it handles html in the label text whereas 'HtmlGenericControl("label")' does not.
            this.fileBrowserLabel = new HtmlGenericControl("label");
            this.fileBrowserLabel.Attributes.Add("class", "formLabel");
            this.fileBrowserLabel.InnerHtml = fileConfig["FileEditPrompt"];
            this.fileBrowserPart.Controls.Add(this.fileBrowserLabel);

            // Set up the file browsing control and add it to the relevant 'form part'.
            this.fileBrowserBox.ID = "fileUpload";
            this.fileBrowserBox.Attributes["class"] = "formControl fileBrowserControl";
            this.fileBrowserPart.Controls.Add(this.fileBrowserBox);

            // Best to use the Label control here because it handles html in the label text whereas 'HtmlGenericControl("label")' does not.
            this.fieldsetLabel = new HtmlGenericControl("legend");
            this.fieldsetLabel.Attributes.Add("class", "formLabel");
            this.fieldsetLabel.InnerHtml = "";
            this.fieldsetPart.Controls.Add(this.fieldsetLabel);

            this.spanFields = new HtmlGenericControl("div");
            this.spanFields.Attributes["class"] = "formControl";
            this.fieldsetPart.Controls.Add(this.spanFields);

            // Add the file attachment id hidden controls and the filename labels
            for (int index = 0; index < maxFiles; index++)
            {
                HtmlInputHidden    idBox        = this.fileIdArray[index];
                HtmlInputHidden    nameBox      = this.fileNameArray[index];
                HtmlGenericControl spanFilename = this.spanFilenameArray[index];
                HtmlGenericControl divFile      = this.divFileArray[index];
                // Give the file data array controls a unique id for adding to the control collection.
                idBox.ID        = "fileId_" + index.ToString(CultureInfo.CurrentCulture);
                nameBox.ID      = "fileName_" + index.ToString(CultureInfo.CurrentCulture);
                spanFilename.ID = "fileLabel_" + index.ToString(CultureInfo.CurrentCulture);
                divFile.ID      = "fileSpace_" + index.ToString(CultureInfo.CurrentCulture);

                // Add the hidden controls to the main control
                this.fieldsetPart.Controls.Add(idBox);
                this.fieldsetPart.Controls.Add(nameBox);

                // Create a dedicated delete button for the file
                EsccButton removeFile = new EsccButton();
                removeFile.ID               = "removeFile_" + index.ToString(CultureInfo.CurrentCulture);
                removeFile.Text             = "Delete";
                removeFile.Click           += new EventHandler(removeFile_Click);
                removeFile.CausesValidation = false;
                removeFile.ValidationGroup  = this.ValidationGroup;

                // Create the div tags for displaying the file and its associated delete button
                HtmlGenericControl spanFileButton = new HtmlGenericControl("span");
                divFile.Attributes["class"] = "attachedFile lowerDottedBorder";
                if (index == 0)
                {
                    divFile.Attributes["class"] += " upperDottedBorder";
                }
                spanFilename.Attributes["class"]   = "attachedFileName";
                spanFileButton.Attributes["class"] = "attachedFileButton";

                // Add the controls to each other
                spanFileButton.Controls.Add(removeFile);
                divFile.Controls.Add(spanFilename);
                divFile.Controls.Add(spanFileButton);
                this.spanFields.Controls.Add(divFile);
            }

            this.fileBrowserLabel.Attributes["for"] = this.fileBrowserBox.UniqueID.Replace("$", "_"); // Wait for this, because box doesn't get its id until it's added to the control tree
        }
        /// <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);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiFileAttachmentBaseControl"/> class.
        /// </summary>
        /// <param name="attachmentType">Defines the type of file attachment this control supports</param>
        /// <param name="maxFiles">The maximum files that will be supported by this control</param>
        /// <param name="validationGroup">The validation group used by this control</param>
        /// <param name="attachmentReference">The attachment reference used by this control (particularly in feedback error messages)</param>
        public MultiFileAttachmentBaseControl(
            string dotnetProjectName,
            MultiFileAttachmentType attachmentType,
            int maxFiles,
            string validationGroup,
            string attachmentReference)
            : base(HtmlTextWriterTag.Fieldset)
        {
            // Set the .NET project name specific for file retrieval from the database.
            this.dotnetProjectName = dotnetProjectName;

            // Set the file attachment type that will be supported by this control
            this.attachmentType = attachmentType;

            // Set the maximum files that will be supported by this control
            this.maxFiles = maxFiles;

            // Set the validation group used by this control
            this.validationGroup = validationGroup;

            // Set the attachment reference used by this control
            this.attachmentReference = attachmentReference;

            // Create the validation summary control
            this.vUploadSummary = new EsccValidationSummary();
            this.vUploadSummary.ValidationGroup = this.validationGroup;

            // Create the 'form part' for the file browser
            this.fileBrowserBox  = new HtmlInputFile();
            this.fileBrowserPart = new HtmlGenericControl("div");
            this.fileBrowserPart.Attributes.Add("class", "formPart");
            this.placePostFileBrowserParts = new PlaceHolder();

            // Create the 'form part' for the 'Add' button control. Enclose the button in a div tag that has the class 'formControl' so
            // that the button will appear a normal button size.
            HtmlGenericControl divAddButton = new HtmlGenericControl("div");

            this.addFile                 = new EsccButton();
            this.addFile.Text            = "Add";
            this.addFile.Click          += new EventHandler(addFile_Click);
            this.addFile.ValidationGroup = this.ValidationGroup;
            divAddButton.Controls.Add(this.addFile);
            this.addButtonPart = new FormPart(string.Empty, divAddButton);

            // Create the 'form part' for the fieldset control
            this.fieldsetPart = new HtmlGenericControl("fieldset");
            this.fieldsetPart.Attributes.Add("class", "formPart");

            // Initialise the file data arrays from page request to page request.
            this.fileIdArray       = new HtmlInputHidden[maxFiles];
            this.fileNameArray     = new HtmlInputHidden[maxFiles];
            this.spanFilenameArray = new HtmlGenericControl[maxFiles];
            this.divFileArray      = new HtmlGenericControl[maxFiles];
            for (int index = 0; index < maxFiles; index++)
            {
                this.fileIdArray[index]       = new HtmlInputHidden();
                this.fileNameArray[index]     = new HtmlInputHidden();
                this.spanFilenameArray[index] = new HtmlGenericControl("span");
                this.divFileArray[index]      = new HtmlGenericControl("div");
            }
        }
        /// <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);
                }
            }
        }