예제 #1
0
        /// <summary>
        /// Creates control hierarchy
        /// </summary>
        protected void CreateControlHierarchy()
        {
            contactFormTable = new Table();
            contactFormTable.CssClass = "contactForm";

            if (DesignMode)
            {
                contactFormTable.BorderWidth = 1;
                contactFormTable.BorderStyle = BorderStyle.Dotted;
            }

            #region "  Control Init  "

            InitializeLabel(ref lblSendError, "Failed to send message");
            lblSendError.CssClass = "sendError";
            lblSendError.Visible = false;

            InitializeLabel(ref lblToName, "To Name: ");
            InitializeLabel(ref lblToAddress, "To Address: ");
            InitializeLabel(ref lblFromName, "From Name: ");
            InitializeLabel(ref lblFromAddress, "From Address: ");
            InitializeLabel(ref lblSubject, "Subject: ");
            InitializeLabel(ref lblMessage, "Message: ");

            InitializeTextBox(ref tbToName, "tbToName", UniqueID);
            InitializeTextBox(ref tbToAddress, "tbToAddress", UniqueID);
            InitializeTextBox(ref tbFromName, "tbFromName", UniqueID);
            InitializeTextBox(ref tbFromAddress, "tbFromAddress", UniqueID);
            InitializeTextBox(ref tbSubject, "tbSubject", UniqueID);
            InitializeTextBox(ref tbMessage, "tbMessage", UniqueID);

            if (btnSend == null)
            {
                btnSend = new Button();
                btnSend.Text = "Send";
            }
            btnSend.CssClass = "btn";
            btnSend.ValidationGroup = UniqueID;

            #endregion

            #region "  Validation Code  "

            validationSummary = new ValidationSummary();
            validationSummary.ValidationGroup = UniqueID;

            InitializeRequiredFieldValidator(ref rfvToName, "rfvToName", tbToAddress.ID,
                UniqueID, "*", "To name is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvToAddress, "rfvToAddress", tbToAddress.ID,
                UniqueID, "*", "To address is required", true, ValidatorDisplay.Dynamic);

            InitializeRegularExpressionValidator(ref revToAddress, "revToAddress", tbToAddress.ID, EmailExpression,
                UniqueID, "*", "To address must be an email address", false, ValidatorDisplay.Static);

            InitializeRequiredFieldValidator(ref rfvFromName, "rfvFromName", tbFromName.ID,
                UniqueID, "*", "From name is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvFromAddress, "rfvFromAddress", tbFromAddress.ID,
                UniqueID, "*", "From address is required", true, ValidatorDisplay.Dynamic);

            InitializeRegularExpressionValidator(ref revFromAddress, "revFromAddress", tbFromAddress.ID, EmailExpression,
                UniqueID, "*", "From address must be an email address", false, ValidatorDisplay.Static);

            InitializeRequiredFieldValidator(ref rfvSubject, "rfvSubject", tbSubject.ID,
                UniqueID, "*", "Subject is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvMessage, "rfvMessage", tbMessage.ID,
                UniqueID, "*", "Message is required", true, ValidatorDisplay.Dynamic);

            validators = new List<IValidator>();
            validators.Add(rfvToName);
            validators.Add(rfvToAddress);
            validators.Add(revToAddress);
            validators.Add(rfvFromName);
            validators.Add(rfvFromAddress);
            validators.Add(revFromAddress);
            validators.Add(rfvSubject);
            validators.Add(rfvMessage);

            #endregion

            #region "  Template Code  "

            if (GreetingTemplate != null)
            {
                greetingTemplateContainer = new GreetingTemplateContainer(this);
                GreetingTemplate.InstantiateIn(greetingTemplateContainer);
                InitalizerPlaceHolder(ref greetingPlaceHolder);
                greetingPlaceHolder.Controls.Add(greetingTemplateContainer);
            }

            if (ThankYouTemplate != null)
            {
                thankYouTemplateContainer = new ThankYouTemplateContainer(this);
                ThankYouTemplate.InstantiateIn(thankYouTemplateContainer);
                InitalizerPlaceHolder(ref thankYouPlaceHolder);
                thankYouPlaceHolder.Controls.Add(thankYouTemplateContainer);
            }

            #endregion

            #region "  Table Code  "

            // To name row
            toNameRow = CreateTableRow(lblToName, tbToName, rfvToName);
            contactFormTable.Rows.Add(toNameRow);

            // To address row
            toAddressRow = CreateTableRow(lblToAddress, tbToAddress,
                rfvToAddress, revToAddress);
            toAddressRow.ID = "toAddressRow";
            contactFormTable.Rows.Add(toAddressRow);

            // From name row
            fromNameRow = CreateTableRow(lblFromName, tbFromName, rfvFromName);
            contactFormTable.Rows.Add(fromNameRow);

            // From address row
            fromAddressRow = CreateTableRow(lblFromAddress, tbFromAddress,
                rfvFromAddress, revFromAddress);
            contactFormTable.Rows.Add(fromAddressRow);

            // Subject row
            TableRow subjectRow = CreateTableRow(lblSubject, tbSubject, rfvSubject);
            contactFormTable.Rows.Add(subjectRow);

            // Message header row
            TableRow messageLabelRow = new TableRow();
            TableCell messageLabelCell = new TableCell();
            messageLabelCell.ColumnSpan = 2;
            messageLabelCell.CssClass = "lblTop";
            messageLabelCell.Controls.Add(lblMessage);
            messageLabelCell.Controls.Add(rfvMessage);
            messageLabelRow.Cells.Add(messageLabelCell);
            contactFormTable.Rows.Add(messageLabelRow);

            // Message text row
            TableRow messageTextRow = new TableRow();
            TableCell messageTextCell = new TableCell();
            messageTextCell.ColumnSpan = 2;
            messageTextCell.CssClass = "ta";
            tbMessage.CssClass = "ta";
            tbMessage.Rows = 3;
            tbMessage.TextMode = TextBoxMode.MultiLine;
            messageTextCell.Controls.Add(tbMessage);
            messageTextRow.Cells.Add(messageTextCell);
            contactFormTable.Rows.Add(messageTextRow);

            // Button row
            btnSend.Click += new EventHandler(btnSend_Click);
            TableRow buttonRow = new TableRow();
            TableCell buttonCell = new TableCell();
            buttonCell.ColumnSpan = 2;
            buttonCell.CssClass = "btn";
            buttonCell.Controls.Add(btnSend);
            buttonRow.Cells.Add(buttonCell);
            contactFormTable.Rows.Add(buttonRow);

            #endregion

            if (!DesignMode)
            {
                _displayMode = ContactFormDisplayMode.Greeting;
            }

            // Add controls to hierarchy
            if (greetingPlaceHolder != null)
            {
                Controls.Add(greetingPlaceHolder);
            }
            Controls.Add(lblSendError);
            Controls.Add(validationSummary);
            Controls.Add(contactFormTable);
            if (thankYouPlaceHolder != null)
            {
                Controls.Add(thankYouPlaceHolder);
            }

            SetVisiblity();
            ChangeDisplayMode();

            ChildControlsCreated = true;
        }
예제 #2
0
        /// <summary>
        /// Creates control hierarchy
        /// </summary>
        protected void CreateControlHierarchy()
        {
            contactFormTable          = new Table();
            contactFormTable.CssClass = "contactForm";

            if (DesignMode)
            {
                contactFormTable.BorderWidth = 1;
                contactFormTable.BorderStyle = BorderStyle.Dotted;
            }

            #region "  Control Init  "

            InitializeLabel(ref lblSendError, "Failed to send message");
            lblSendError.CssClass = "sendError";
            lblSendError.Visible  = false;

            InitializeLabel(ref lblToName, "To Name: ");
            InitializeLabel(ref lblToAddress, "To Address: ");
            InitializeLabel(ref lblFromName, "From Name: ");
            InitializeLabel(ref lblFromAddress, "From Address: ");
            InitializeLabel(ref lblSubject, "Subject: ");
            InitializeLabel(ref lblMessage, "Message: ");

            InitializeTextBox(ref tbToName, "tbToName", UniqueID);
            InitializeTextBox(ref tbToAddress, "tbToAddress", UniqueID);
            InitializeTextBox(ref tbFromName, "tbFromName", UniqueID);
            InitializeTextBox(ref tbFromAddress, "tbFromAddress", UniqueID);
            InitializeTextBox(ref tbSubject, "tbSubject", UniqueID);
            InitializeTextBox(ref tbMessage, "tbMessage", UniqueID);

            if (btnSend == null)
            {
                btnSend      = new Button();
                btnSend.Text = "Send";
            }
            btnSend.CssClass        = "btn";
            btnSend.ValidationGroup = UniqueID;

            #endregion

            #region "  Validation Code  "

            validationSummary = new ValidationSummary();
            validationSummary.ValidationGroup = UniqueID;

            InitializeRequiredFieldValidator(ref rfvToName, "rfvToName", tbToAddress.ID,
                                             UniqueID, "*", "To name is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvToAddress, "rfvToAddress", tbToAddress.ID,
                                             UniqueID, "*", "To address is required", true, ValidatorDisplay.Dynamic);

            InitializeRegularExpressionValidator(ref revToAddress, "revToAddress", tbToAddress.ID, EmailExpression,
                                                 UniqueID, "*", "To address must be an email address", false, ValidatorDisplay.Static);

            InitializeRequiredFieldValidator(ref rfvFromName, "rfvFromName", tbFromName.ID,
                                             UniqueID, "*", "From name is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvFromAddress, "rfvFromAddress", tbFromAddress.ID,
                                             UniqueID, "*", "From address is required", true, ValidatorDisplay.Dynamic);

            InitializeRegularExpressionValidator(ref revFromAddress, "revFromAddress", tbFromAddress.ID, EmailExpression,
                                                 UniqueID, "*", "From address must be an email address", false, ValidatorDisplay.Static);

            InitializeRequiredFieldValidator(ref rfvSubject, "rfvSubject", tbSubject.ID,
                                             UniqueID, "*", "Subject is required", true, ValidatorDisplay.Dynamic);

            InitializeRequiredFieldValidator(ref rfvMessage, "rfvMessage", tbMessage.ID,
                                             UniqueID, "*", "Message is required", true, ValidatorDisplay.Dynamic);

            validators = new List <IValidator>();
            validators.Add(rfvToName);
            validators.Add(rfvToAddress);
            validators.Add(revToAddress);
            validators.Add(rfvFromName);
            validators.Add(rfvFromAddress);
            validators.Add(revFromAddress);
            validators.Add(rfvSubject);
            validators.Add(rfvMessage);

            #endregion

            #region "  Template Code  "

            if (GreetingTemplate != null)
            {
                greetingTemplateContainer = new GreetingTemplateContainer(this);
                GreetingTemplate.InstantiateIn(greetingTemplateContainer);
                InitalizerPlaceHolder(ref greetingPlaceHolder);
                greetingPlaceHolder.Controls.Add(greetingTemplateContainer);
            }

            if (ThankYouTemplate != null)
            {
                thankYouTemplateContainer = new ThankYouTemplateContainer(this);
                ThankYouTemplate.InstantiateIn(thankYouTemplateContainer);
                InitalizerPlaceHolder(ref thankYouPlaceHolder);
                thankYouPlaceHolder.Controls.Add(thankYouTemplateContainer);
            }

            #endregion

            #region "  Table Code  "

            // To name row
            toNameRow = CreateTableRow(lblToName, tbToName, rfvToName);
            contactFormTable.Rows.Add(toNameRow);

            // To address row
            toAddressRow = CreateTableRow(lblToAddress, tbToAddress,
                                          rfvToAddress, revToAddress);
            toAddressRow.ID = "toAddressRow";
            contactFormTable.Rows.Add(toAddressRow);

            // From name row
            fromNameRow = CreateTableRow(lblFromName, tbFromName, rfvFromName);
            contactFormTable.Rows.Add(fromNameRow);

            // From address row
            fromAddressRow = CreateTableRow(lblFromAddress, tbFromAddress,
                                            rfvFromAddress, revFromAddress);
            contactFormTable.Rows.Add(fromAddressRow);

            // Subject row
            TableRow subjectRow = CreateTableRow(lblSubject, tbSubject, rfvSubject);
            contactFormTable.Rows.Add(subjectRow);

            // Message header row
            TableRow  messageLabelRow  = new TableRow();
            TableCell messageLabelCell = new TableCell();
            messageLabelCell.ColumnSpan = 2;
            messageLabelCell.CssClass   = "lblTop";
            messageLabelCell.Controls.Add(lblMessage);
            messageLabelCell.Controls.Add(rfvMessage);
            messageLabelRow.Cells.Add(messageLabelCell);
            contactFormTable.Rows.Add(messageLabelRow);

            // Message text row
            TableRow  messageTextRow  = new TableRow();
            TableCell messageTextCell = new TableCell();
            messageTextCell.ColumnSpan = 2;
            messageTextCell.CssClass   = "ta";
            tbMessage.CssClass         = "ta";
            tbMessage.Rows             = 3;
            tbMessage.TextMode         = TextBoxMode.MultiLine;
            messageTextCell.Controls.Add(tbMessage);
            messageTextRow.Cells.Add(messageTextCell);
            contactFormTable.Rows.Add(messageTextRow);

            // Button row
            btnSend.Click += new EventHandler(btnSend_Click);
            TableRow  buttonRow  = new TableRow();
            TableCell buttonCell = new TableCell();
            buttonCell.ColumnSpan = 2;
            buttonCell.CssClass   = "btn";
            buttonCell.Controls.Add(btnSend);
            buttonRow.Cells.Add(buttonCell);
            contactFormTable.Rows.Add(buttonRow);

            #endregion

            if (!DesignMode)
            {
                _displayMode = ContactFormDisplayMode.Greeting;
            }

            // Add controls to hierarchy
            if (greetingPlaceHolder != null)
            {
                Controls.Add(greetingPlaceHolder);
            }
            Controls.Add(lblSendError);
            Controls.Add(validationSummary);
            Controls.Add(contactFormTable);
            if (thankYouPlaceHolder != null)
            {
                Controls.Add(thankYouPlaceHolder);
            }

            SetVisiblity();
            ChangeDisplayMode();

            ChildControlsCreated = true;
        }