protected void Page_Load(object sender, EventArgs e) { FormGeneratorData d = new FormGeneratorData(); MasterPage mp = Page.Master; this.Form.ID = d.GetPageByPageID(pageID).Rows[0]["FormName"].ToString(); DataTable dtControls = d.GetPageControlsByPageID(pageID); foreach (DataRow dr in dtControls.Rows) { string pageControl_ID = dr["pageControl_ID"].ToString(); string phID = dr["ASP_ID"].ToString(); string type = dr["TypeName"].ToString(); PlaceHolder ph = (PlaceHolder)mp.FindControl(phID); DataTable dtProperties = d.GetPageControlPropertyValuesByPageControl_ID(pageControl_ID); if (type == "TextBox") { TextBox tb = new TextBox(); tb.ID = dr["AprimoFieldName"].ToString(); tb.CssClass = dr["CssClass"].ToString(); tb.Attributes.Add("placeholder", dr["Watermark"].ToString()); tb.Attributes.Add("validate", dr["DoValidate"].ToString()); tb.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); ph.Controls.Add(tb); } else if (type == "ListBox") { DataTable dt = d.GetControlOptionsByPageControl_ID(dr["PageControl_ID"].ToString()); ListBox lb = new ListBox(); lb.ID = dr["AprimoFieldName"].ToString(); lb.CssClass = dr["CssClass"].ToString(); lb.SelectionMode = ListSelectionMode.Multiple; lb.Attributes.Add("validate", dr["DoValidate"].ToString()); lb.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); FormGeneratorTools.BindObject(lb, dt, "Text", "Value", "Select One"); ph.Controls.Add(lb); } else if (type == "DropDownList") { DataTable dt = d.GetControlOptionsByPageControl_ID(dr["PageControl_ID"].ToString()); DropDownList ddl = new DropDownList(); ddl.ID = dr["AprimoFieldName"].ToString(); ddl.CssClass = dr["CssClass"].ToString(); ddl.Attributes.Add("validate", dr["DoValidate"].ToString()); ddl.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); FormGeneratorTools.BindObject(ddl, dt, "Text", "Value", "Select One"); ph.Controls.Add(ddl); } else if (type == "Multi-line") { TextBox tb = new TextBox(); tb.ID = dr["AprimoFieldName"].ToString(); tb.CssClass = dr["CssClass"].ToString(); tb.TextMode = TextBoxMode.MultiLine; tb.Attributes.Add("placeholder", dr["Watermark"].ToString()); tb.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); tb.Attributes.Add("validate", dr["DoValidate"].ToString()); ph.Controls.Add(tb); } else if (type == "Literal") { Literal lit = new Literal(); lit.ID = dr["AprimoFieldName"].ToString(); SetControlProperties(lit, dtProperties); ph.Controls.Add(lit); } else if (type == "Image") { Image img = new Image(); SetControlProperties(img, dtProperties); ph.Controls.Add(img); } else if (type == "Submit") { Button submit = new Button(); submit.Text = "Submit"; submit.OnClientClick = "return IsValid()"; submit.Click += new EventHandler(submit_Click); submit.ID = dr["AprimoFieldName"].ToString(); ph.Controls.Add(submit); } ph.Controls.Add(new LiteralControl("<br />")); } }
protected void rptrPageControls_ItemCommand(object source, RepeaterCommandEventArgs e) { FormGeneratorData data = new FormGeneratorData(); HiddenField hf = (HiddenField)e.Item.FindControl("hidPageControlID"); DataTable dtProperties = data.GetPageControlPropertyValuesByPageControl_ID(hf.Value); if (dtProperties.Rows.Count > 0) { if (dtProperties.Rows[0]["ControlList_Name"].ToString() == "Content Block") { pnlEditActions.Visible = false; pnlAddEditDropdown.Visible = false; pnlAddEditTextBox.Visible = false; pnlAddEditContentBlock.Visible = true; pnlAddSubmitButton.Visible = false; btnAdd.Visible = true; txtRTE.Text = dtProperties.Rows[0]["SettingValue"].ToString(); btnRTECancel.Visible = true; btnUpdateRTE.Visible = true; } else if (dtProperties.Rows[0]["ControlList_Name"].ToString() == "Submit") { pnlEditActions.Visible = false; pnlAddEditDropdown.Visible = false; pnlAddEditTextBox.Visible = false; pnlAddEditContentBlock.Visible = false; pnlAddSubmitButton.Visible = true; btnAdd.Visible = true; txtButtonText.Text = dtProperties.Rows[0]["SettingValue"].ToString(); } hfPageControlSetting_ID.Value = dtProperties.Rows[0]["PageControlSetting_ID"].ToString(); hfControlListID_ForEdit.Value = dtProperties.Rows[0]["ControlList_ID"].ToString(); hfPageControlID_ForEdit.Value = dtProperties.Rows[0]["PageControl_ID"].ToString(); } if (e.CommandName.ToString() == "delete") { data.RemovePageControl(e.CommandArgument.ToString()); LoadDropdown(ddlControlList, data.GetAvalableControlsByPage_ID(ddlPages.SelectedValue), "name", "controllist_id", "Select Field"); pnlControlList.Visible = true; btnAdd.Visible = true; pnlAddEditDropdown.Visible = false; pnlAddEditContentBlock.Visible = false; pnlAddEditTextBox.Visible = false; pnlAddSubmitButton.Visible = false; LogMessage("Deleted Field From Form."); } else // Edit { pnlControlList.Visible = false; DataTable dtControlInfo = data.GetControlInfoByPageControl_ID(hf.Value); string controlType = dtControlInfo.Rows[0]["ControlType"].ToString(); if (controlType == "TextBox" || controlType == "Multi-line") { pnlEditActions.Visible = false; pnlAddEditDropdown.Visible = false; pnlAddEditTextBox.Visible = true; pnlAddEditContentBlock.Visible = false; btnAdd.Visible = true; hfControlListID_ForEdit.Value = dtControlInfo.Rows[0]["ControlList_ID"].ToString(); hfPageControlID_ForEdit.Value = hf.Value; } else if (controlType == "DropDownList") { pnlEditActions.Visible = false; pnlAddEditDropdown.Visible = true; pnlAddEditTextBox.Visible = false; pnlAddEditContentBlock.Visible = false; btnAdd.Visible = false; hfPageControlID_DD_ForEdit.Value = hf.Value; DataTable dtOptions = data.GetControlOptionsByPageControl_ID(hf.Value); string defaultValue = data.GetDefaultOptionByPageControl_ID(hf.Value); txtDefaultOption.Text = defaultValue; rptrOptions.DataSource = dtOptions; rptrOptions.DataBind(); } else if (controlType == "Submit") { pnlEditActions.Visible = true; pnlAddSubmitButton.Visible = true; pnlControlList.Visible = false; btnUpdateButtonText.Visible = true; hfPageControlID_Action_ForEdit.Value = hf.Value; hfPageControlID_ForEdit.Value = hf.Value; DataTable dtActionTypes = data.GetControlActionTypes(); DataTable dtActions = data.GetControlActionsByPageControl_ID(hf.Value); DataTable dtAprimoInfo = data.GetAprimoInfoByPage_ID(ddlPages.SelectedValue); if (dtAprimoInfo != null) { txtAprimoSubject.Text = dtAprimoInfo.Rows[0]["Subject"].ToString(); txtAprimoID.Text = dtAprimoInfo.Rows[0]["Aprimo_ID"].ToString(); } LoadDropdown(ddlActions, dtActionTypes, "Name", "ControlActionType_ID", "Select Action"); rptrActions.DataSource = dtActions; rptrActions.DataBind(); if (ddlPages.SelectedIndex != 0) { if (data.DoesPagehaveECASControlAction(ddlPages.SelectedValue)) { string url = ""; if (ddlPages.SelectedIndex != 0) url = data.GetReturnURLByPage_ID(ddlPages.SelectedValue); tbxReturnURL.Text = url; pnlReturnURL.Visible = true; } } } } ReloadControlList(); }
protected void btnSaveOption_Click(object sender, EventArgs e) { FormGeneratorData data = new FormGeneratorData(); if (txtText.Text != "" && txtValue.Text != "") { if (hfControlOptionID_ForEdit.Value == "") { data.AddControlOption(hfPageControlID_DD_ForEdit.Value, txtText.Text, txtValue.Text); LogMessage("Added Dropdown Option."); } else { data.UpdateControlOption(hfControlOptionID_ForEdit.Value, txtText.Text, txtValue.Text); hfControlOptionID_ForEdit.Value = ""; LogMessage("Updated Dropdown Option."); } txtText.Text = ""; txtValue.Text = ""; btnSaveOption.Text = "Add"; } if (txtDefaultOption.Text != "") data.SavePageControlDefaultOption(txtDefaultOption.Text, hfPageControlID_DD_ForEdit.Value); DataTable dtOptions = data.GetControlOptionsByPageControl_ID(hfPageControlID_DD_ForEdit.Value); rptrOptions.DataSource = dtOptions; rptrOptions.DataBind(); }
protected void rptrOptions_ItemCommand(object source, RepeaterCommandEventArgs e) { string controlOption_ID = e.CommandArgument.ToString(); FormGeneratorData data = new FormGeneratorData(); if (e.CommandName.ToString() == "delete") { data.RemoveControlOption(controlOption_ID); DataTable dtOptions = data.GetControlOptionsByPageControl_ID(hfPageControlID_DD_ForEdit.Value); rptrOptions.DataSource = dtOptions; rptrOptions.DataBind(); } else if (e.CommandName.ToString() == "edit") { hfControlOptionID_ForEdit.Value = e.CommandArgument.ToString(); DataTable dt = data.GetControlOptionsByControlOption_ID(controlOption_ID); txtText.Text = dt.Rows[0]["Text"].ToString(); txtValue.Text = dt.Rows[0]["Value"].ToString(); //load default btnSaveOption.Text = "Save"; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { HttpBrowserCapabilities browser = Request.Browser; FormGeneratorData d = new FormGeneratorData(); MasterPage mp = Page.Master; DataTable dtForm = d.GetPageByPageID(pageID); if (dtForm.Rows.Count > 0) { this.Form.ID = dtForm.Rows[0]["FormName"].ToString(); if (dtForm.Rows[0]["CSSClass"] != DBNull.Value) this.Form.Attributes.Add("class", dtForm.Rows[0]["CSSClass"].ToString()); if (dtForm.Rows[0]["Tracking_Campaign"] != DBNull.Value) { HiddenField hfCampaign = new HiddenField(); hfCampaign.ID = "c"; hfCampaign.Value = dtForm.Rows[0]["Tracking_Campaign"].ToString(); this.Form.Controls.Add(hfCampaign); } if (dtForm.Rows[0]["Tracking_Source"] != DBNull.Value) { HiddenField hfSource = new HiddenField(); hfSource.ID = "s"; hfSource.Value = dtForm.Rows[0]["Tracking_Source"].ToString(); this.Form.Controls.Add(hfSource); } if (dtForm.Rows[0]["Tracking_Page"] != DBNull.Value) { HiddenField hfPage = new HiddenField(); hfPage.ID = "_p"; hfPage.Value = dtForm.Rows[0]["Tracking_Page"].ToString(); this.Form.Controls.Add(hfPage); } } else return; object aprimoID = dtForm.Rows[0]["Aprimo_ID"]; object subjectLine = dtForm.Rows[0]["Subject"]; object isModal = dtForm.Rows[0]["IsModal"]; if (isModal != null) { bool isModalForm = Convert.ToBoolean(isModal); PlaceHolder ph = (PlaceHolder)mp.FindControl("phHidden"); HtmlGenericControl hidden = new HtmlGenericControl(); hidden.TagName = "input"; hidden.ID = "hidIsModal"; hidden.Attributes.Add("type", "hidden"); if (isModalForm) hidden.Attributes.Add("value", "true"); else hidden.Attributes.Add("value", "false"); ph.Controls.Add(hidden); } if (aprimoID != null) this.Form.Attributes.Add("AprimoID", aprimoID.ToString()); if (subjectLine != null) this.Form.Attributes.Add("AprimoSubject", subjectLine.ToString()); DataTable dtControls = d.GetPageControlsByPageID(pageID); foreach (DataRow dr in dtControls.Rows) { string pageControl_ID = dr["pageControl_ID"].ToString(); string phID = dr["ASP_ID"].ToString(); string type = dr["TypeName"].ToString(); PlaceHolder ph = (PlaceHolder)mp.FindControl(phID); DataTable dtProperties = d.GetPageControlPropertyValuesByPageControl_ID(pageControl_ID); string isRequired = dr["IsRequired"].ToString(); if (type == "TextBox") { CrossBrowser_TextBox c = (CrossBrowser_TextBox)LoadControl("Controls/CrossBrowser_TextBox.ascx"); string controlName = dr["Type"].ToString().ToLower(); if (isRequired == "True") c.Watermark = dr["Watermark"].ToString() + " *"; else c.Watermark = dr["Watermark"].ToString(); c.tbxCrossBrowser.ID = dr["AprimoFieldName"].ToString(); c.tbxCrossBrowser.CssClass = dr["CssClass"].ToString(); c.tbxCrossBrowser.Attributes.Add("validate", dr["DoValidate"].ToString()); c.tbxCrossBrowser.Attributes.Add("controlname", dr["Type"].ToString().ToLower()); if (controlName == "company") { c.tbxCrossBrowser.ClientIDMode = ClientIDMode.Static; c.tbxCrossBrowser.ID = "company"; } ph.Controls.Add(c); } else if (type == "ListBox") { DataTable dt = d.GetControlOptionsByPageControl_ID(dr["PageControl_ID"].ToString()); ListBox lb = new ListBox(); lb.ID = dr["AprimoFieldName"].ToString(); lb.CssClass = dr["CssClass"].ToString(); lb.SelectionMode = ListSelectionMode.Multiple; lb.Attributes.Add("validate", dr["DoValidate"].ToString()); lb.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); FormGeneratorTools.BindObject(lb, dt, "Text", "Value", "Select One"); ph.Controls.Add(lb); ph.Controls.Add(new LiteralControl("<br />")); } else if (type == "DropDownList") { DropDownList ddl = new DropDownList(); bool hasConstantValues = Convert.ToBoolean(dr["HasConstantValues"]); DataTable dt; if (hasConstantValues) { dt = d.GetControlConstantValues(dr["ControlList_ID"].ToString()); FormGeneratorTools.BindObject(ddl, dt, "Text", "Value", dr["type"].ToString()); } else { dt = d.GetControlOptionsByPageControl_ID(dr["PageControl_ID"].ToString()); string defaultValue = ""; if (dr["DefaultValue"] != null) defaultValue = dr["DefaultValue"].ToString(); FormGeneratorTools.BindObject(ddl, dt, "Text", "Value", defaultValue); } ddl.ID = dr["AprimoFieldName"].ToString(); ddl.CssClass = dr["CssClass"].ToString(); ddl.Attributes.Add("validate", dr["DoValidate"].ToString()); ddl.Attributes.Add("controlName", dr["Type"].ToString().ToLower()); if (isRequired == "True") ddl.Items[0].Text = ddl.Items[0].Text + " *"; ph.Controls.Add(ddl); ph.Controls.Add(new LiteralControl("<br />")); } else if (type == "Multi-line") { CrossBrowser_TextArea c = (CrossBrowser_TextArea)LoadControl("Controls/CrossBrowser_TextArea.ascx"); c.Watermark = dr["Watermark"].ToString(); c.tbxCrossBrowser.ID = dr["AprimoFieldName"].ToString(); c.tbxCrossBrowser.CssClass = dr["CssClass"].ToString(); c.tbxCrossBrowser.Attributes.Add("validate", dr["DoValidate"].ToString()); c.tbxCrossBrowser.Attributes.Add("controlname", dr["Type"].ToString().ToLower()); if (isRequired == "True") c.Watermark = dr["Watermark"].ToString() + " *"; else c.Watermark = dr["Watermark"].ToString(); ph.Controls.Add(c); //ph.Controls.Add(new LiteralControl("<br />")); } else if (type == "Literal") { Literal lit = new Literal(); lit.ID = dr["AprimoFieldName"].ToString(); SetControlProperties(lit, dtProperties); ph.Controls.Add(lit); ph.Controls.Add(new LiteralControl("<br />")); } else if (type == "Submit") { string errorMessage = "Please fix errors."; string successMessage = "Submitted successfully!"; CrossBrowser_Button c = (CrossBrowser_Button)LoadControl("Controls/CrossBrowser_Button.ascx"); c.ID = "cbbSubmit"; c.ehButtonClicked += new EventHandler(submit_Click); c.txtCrossBrowserSubmit.CssClass = dr["CssClass"].ToString(); c.txtCrossBrowserSubmit.Text = d.GetControlProperty(dr["PageControl_ID"].ToString(), "Text"); c.txtCrossBrowserSubmit.OnClientClick = "return IsValid()"; c.txtCrossBrowserSubmit.ID = dr["AprimoFieldName"].ToString(); c.txtCrossBrowserSubmit.Attributes.Add("pageControlID", dr["PageControl_ID"].ToString()); c.ErrorMessage = errorMessage; c.SuccessMessage = successMessage; //c.lblErrorMessage.Text = errorMessage; c.lblSuccessMessage.Text = successMessage; ph.Controls.Add(c); ph.Controls.Add(new LiteralControl("<br />")); } } HtmlGenericControl dbFormHidden = new HtmlGenericControl("div"); dbFormHidden.ID = "db-form-hidden"; Page.Controls.Add(dbFormHidden); HtmlGenericControl tracking = new HtmlGenericControl("div"); tracking.ID = "trackingFields"; Page.Controls.Add(tracking); HiddenField hf = new HiddenField(); hf.ID = "hfDBResults"; hf.Visible = true; HtmlGenericControl wrapper = new HtmlGenericControl("div"); wrapper.Controls.Add(hf); Page.Form.Controls.Add(wrapper); Page.Controls.Add(new LiteralControl(@" <script type='text/javascript'> $(document).ready(function(){ initAutocomplete(); getResultsIP(); renderHiddenTrackingFields(); if($('.ui-autocomplete-input').attr('name') == '') $('.ui-autocomplete-input').hide(); }) </script> ")); } }