using System;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using CMS.CMSHelper;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.ResourceManager;
using CMS.SettingsProvider;
using CMS.SiteProvider;
[ValidationPropertyAttribute("Value")]
public partial class CMSFormControls_System_CodeName : FormEngineUserControl
{
#region "Properties"
///
/// Gets or sets whether the control is read only
///
public bool ReadOnly
{
get
{
return textbox.ReadOnly;
}
set
{
textbox.ReadOnly = value;
}
}
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
if (textbox != null)
{
textbox.Enabled = value;
}
}
}
///
/// Gets or sets form control value.
///
public override object Value
{
get
{
// Get the text
string text = textbox.Text;
if (String.IsNullOrEmpty(text) && !ExternalValue)
{
// Automatic code name in case of empty value
text = BaseInfo.CODENAME_AUTOMATIC;
}
return text;
}
set
{
string stringValue = ValidationHelper.GetString(value, "");
// Mark external value
if (!String.IsNullOrEmpty(stringValue) && !RequestHelper.IsPostBack())
{
ExternalValue = true;
}
textbox.Text = stringValue;
}
}
///
/// Returns client ID of the textbox.
///
public override string ValueElementID
{
get
{
return textbox.ClientID;
}
}
///
/// Publicly visible textbox
///
public TextBox TextBox
{
get
{
return textbox;
}
}
///
/// Maximum length of plain text or resource string key. Validates in IsValid() method.
///
public int MaxLength
{
get
{
return textbox.MaxLength;
}
set
{
textbox.MaxLength = value;
}
}
///
/// Indicates if control is used on live site. Default value is FALSE for localizable text box.
///
public override bool IsLiveSite
{
get;
set;
}
///
/// If true, the hint is shown
///
public bool ShowHint
{
get
{
return imgHelp.Visible;
}
set
{
imgHelp.Visible = value;
}
}
///
/// If true, the value was set externally
///
protected bool ExternalValue
{
get
{
return ValidationHelper.GetBoolean(ViewState["ExternalValue"], false);
}
set
{
ViewState["ExternalValue"] = value;
}
}
#endregion
#region "Methods"
protected void Page_Load(object sender, EventArgs e)
{
imgHelp.ImageUrl = GetImageUrl("CMSModules/CMS_Settings/help.png");
imgHelp.ToolTip = GetString("codename.tooltip");
if (Enabled)
{
imgHelp.ToolTip += " " + GetString("codename.tooltipedit");
}
// Apply CSS style
if (!String.IsNullOrEmpty(CssClass))
{
textbox.CssClass = CssClass;
CssClass = null;
}
else
{
textbox.CssClass = "TextBoxField";
}
if (String.IsNullOrEmpty(textbox.Text))
{
if (!ExternalValue)
{
textbox.WatermarkText = "(automatic)";
textbox.WatermarkCssClass = "CodeNameTextBoxInactive";
}
}
else
{
textbox.Attributes.Add("onfocus", "this.className = '" + textbox.CssClass + "'");
textbox.CssClass += " CodeNameTextBoxInactive";
}
textbox.TabIndex = -1;
}
///
/// Validates control.
///
public override bool IsValid()
{
// Check for maximum length
if (MaxLength > 0)
{
return (textbox.Text.Length <= MaxLength);
}
else
{
return true;
}
}
#endregion
}