You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
7.3 KiB
201 lines
7.3 KiB
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></{0}:TextboxEx>")]
|
|
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 = " <script language=\"javascript\" type=\"text/javascript\">"
|
|
+ " function check" + ID + "(){"
|
|
+ " var name = document.getElementById(\"" + ClientID + "\").value;";
|
|
if (ControlToCompare != "")
|
|
str += " var compare = document.getElementById(\"" + ControlToCompare + "\").value;";
|
|
str += " " + ajaxRegisterType + "." + AjaxMethod + "(name,";
|
|
if (controlToCompare != "")
|
|
str += "compare,";
|
|
str += " check" + ID + "_Callback);"
|
|
+ " }"
|
|
+ " function check" + ID + "_Callback(res){ "
|
|
+ " if(res.value==\"OK\"){"
|
|
+ " document.getElementById(\"Div" + ID + "\").innerHTML = \"" + successDivText + "\";"
|
|
+ " document.getElementById(\"Div" + ID + "\").className = \"NullDiv\";"
|
|
+ " }"
|
|
+ " else if( res.value==\"ERR\"){"
|
|
+ " document.getElementById(\"Div" + ID + "\").innerHTML = \"" + ErrorDivText + "\";"
|
|
+ " document.getElementById(\"Div" + ID + "\").className = \"AlertDiv\";"
|
|
+ " }"
|
|
+ " else"
|
|
+ " {"
|
|
+ " document.getElementById(\"Div" + ID + "\").innerHTML = \"" + DivText + "\";"
|
|
+ " document.getElementById(\"Div" + ID + "\").className = \"NullDiv\";"
|
|
+ " }"
|
|
+ " }"
|
|
+ " </script>";
|
|
writer.Write(str);
|
|
}
|
|
|
|
string dw = ((divWidth != "") ? " width='" + divWidth + "' " : "");
|
|
writer.Write("<table cellpadding='0' cellspacing='0' border='0' class='NullTable'><tr><td align='left'>");
|
|
if (onlyShowAlertDiv == false)
|
|
base.Render(writer);
|
|
writer.Write("</td><td width='" + textDivInterval.ToString() + "' ></td><td " + dw + ">");
|
|
writer.Write("<div id='Div" + ID + "' class='NullDiv'" + dw + ">" + divText + "</div>");
|
|
writer.Write("<div id='FocusDiv" + ID + "' class='InfoDiv'" + dw + " style='display:none'>" + FocusDivText + "</div>");
|
|
writer.Write("</td></tr></table>");
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|