using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.Web; namespace WebBase { [DefaultProperty("Text")] [ToolboxData("<{0}:TextboxEx runat=server>")] public class TextboxEx : TextBox { #region BackColorOff private Color _colOff = Color.White; [Category("扩展"), Description("The background color when the control loses focus")] public Color BackColorOff { get { return _colOff; } set { _colOff = value; } } #endregion #region BackColorOn private Color _colOn = Color.FromArgb(255, 255, 225); [Category("扩展"), Description("The background color when the control has the focus")] public Color BackColorOn { get { return _colOn; } set { _colOn = value; } } #endregion #region TextDivInterval private int textDivInterval = 15; [Category("扩展"), Description("输入框和提示框之间的间隔")] public int TextDivInterval { get { return textDivInterval; } set { textDivInterval = value; } } #endregion #region DivWidth private string divWidth = "400px"; [Category("扩展"), Description("提示框的宽度")] public string DivWidth { get { return divWidth; } set { divWidth = value; } } #endregion #region DivText private string divText = ""; [Category("扩展"), Description("提示框的默认的文字")] public string DivText { get { return divText; } set { divText = value; } } #endregion #region FocusDivText private string focusDivText = ""; [Category("扩展"), Description("输入框激活时提示框中显示的文字")] public string FocusDivText { get { if (focusDivText == "") return divText; else return focusDivText; } set { focusDivText = value; } } #endregion #region ErrorDivText private string errorDivText = ""; [Category("扩展"), Description("输入框输入错误时提示框中显示的文字")] public string ErrorDivText { get { return errorDivText; } set { errorDivText = value; } } #endregion #region SuccessDivText private string successDivText = ""; [Category("扩展"), Description("输入框输入成功时提示框中显示的文字")] public string SuccessDivText { get { return successDivText; } set { successDivText = value; } } #endregion #region OnlyShowAlertDiv private bool onlyShowAlertDiv = false; [Category("扩展"), Description("只是显示提示框,输入框不显示,用于与其他控件的配合使用")] public bool OnlyShowAlertDiv { get { return onlyShowAlertDiv; } set { onlyShowAlertDiv = value; } } #endregion #region AjaxRegisterType private string ajaxRegisterType = ""; [Category("扩展"), Description("Ajax对应注册的名称,通常指在页面中AjaxPro.Utility.RegisterTypeForAjax(typeof(name))中的name")] public string AjaxRegisterType { get { return ajaxRegisterType; } set { ajaxRegisterType = value; } } #endregion #region AjaxMethod private string ajaxMethod = ""; [Category("扩展"), Description("Ajax对应的函数,通常指在页面中标有AjaxPro.AjaxMethod()的函数")] public string AjaxMethod { get { if (ajaxMethod == "") ajaxMethod = "check" + ID; return ajaxMethod; } set { ajaxMethod = value; } } #endregion private string controlToCompare = ""; public string ControlToCompare { get { return controlToCompare; } set { controlToCompare = value; } } protected override void Render(HtmlTextWriter writer) { if (ajaxRegisterType != "") { string str = " "; writer.Write(str); } string dw = ((divWidth != "") ? " width='" + divWidth + "' " : ""); writer.Write("
"); if (onlyShowAlertDiv == false) base.Render(writer); writer.Write(""); writer.Write("
" + divText + "
"); writer.Write(""); writer.Write("
"); } protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); string foc = "Div" + ID + ".style.display='none';"; if (FocusDivText != "") foc += "FocusDiv" + ID + ".style.display='block';"; writer.AddAttribute("onFocus", foc); string blurText = divText; if (successDivText != "") blurText = successDivText; string blur = " Div" + ID + ".style.display='block';FocusDiv" + ID + ".style.display='none';"; //if (AjaxObject != "") blur += "check" + ID + "();"; writer.AddAttribute("onBlur", blur); } } }