?? webcustomcontrol1.cs
字號:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
namespace Example.第4章._40.如何創(chuàng)建自定義驗證控件
{
/// <summary>
/// WebCustomControl1 的摘要說明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.RequiredFieldValidator
{
[Bindable(true),
Category("Appearance"),
Description( "用于指定被驗證控件輸入的字符位數(shù)" ),
DefaultValue(0)]
public int len
{
get
{
object lens = this.ViewState["len"];
if (lens != null)
return Convert.ToInt32(this.ViewState["len"]);
else
return 0;
}
set
{
ViewState["len"] = value;
}
}
/// <summary>
/// 將此控件呈現(xiàn)給指定的輸出參數(shù)。
/// </summary>
/// <param name="output"> 要寫出到的 HTML 編寫器 </param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if(Page.IsPostBack)
{
if (this.Enabled)
{
string ValidateID = this.ControlToValidate;
string context = ((TextBox)Page.FindControl(ValidateID)).Text.Trim();
if(context.Length != this.len)
{
this.IsValid = false;
}
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -