using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.UIControls; using CMS.GlobalHelper; using CMS.FormEngine; using CMS.FormControls; [Security(ValidateHash = true)] [Title("CMSModules/CMS_PortalEngine/OnSiteEdit/EditText.png", "General.EditProperty", "EditProperty")] public partial class CMSModules_PortalEngine_UI_WebParts_EditProperty : CMSModalPage { /// /// Form control /// protected FormEngineUserControl FormControl { get; set; } /// /// Underlying element ID /// protected string ElementID { get; set; } /// /// Init event handler /// protected override void OnInit(EventArgs e) { base.OnInit(e); ElementID = QueryHelper.GetString("elementid", ""); if (!RequestHelper.IsPostBack()) { // Load the initialization script which pulls the value from the opener ScriptHelper.RegisterStartupScript(this, typeof(string), "LoadValue", ScriptHelper.GetScript(String.Format( "document.getElementById('{0}').value = wopener.document.getElementById('{1}').value; {2}", hdnValue.ClientID, ElementID, ClientScript.GetPostBackEventReference(btnLoad, null) ))); } else { // Load the form control string formControl = QueryHelper.GetString("formcontrol", ""); // Load the form control var ctrl = FormControlsHelper.LoadFormControl(Page, formControl, ""); if (ctrl != null) { plcControl.Controls.Add(ctrl); } FormControl = ctrl; } } /// /// Loads the form control value from the hidden field /// protected void btnLoad_Click(object sender, EventArgs e) { FormControl.Value = hdnValue.Value; } /// /// Saves the form control value back to the element /// protected void btnOK_Click(object sender, EventArgs e) { string newValue = ValidationHelper.GetString(FormControl.Value, ""); // Check if empty if (String.IsNullOrEmpty(HTMLHelper.StripTags(newValue).Trim())) { ShowError(GetString("general.requiresvalue")); return; } hdnValue.Value = newValue; FormControl.Visible = false; ScriptHelper.RegisterStartupScript(this, typeof(string), "LoadValue", ScriptHelper.GetScript(String.Format( @" var e = wopener.document.getElementById('{1}'); e.value = document.getElementById('{0}').value; if (e.save) e.save(); CloseDialog(); ", hdnValue.ClientID, ElementID ))); } }