`

简单的验证文本框数字的web控件

阅读更多

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebControlNumberText
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:TextBoxNumber runat=server></{0}:TextBoxNumber>")]
public class TextBoxNumber : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text"] = value;
}
}
new public string ID
{
get
{
String s = (String)ViewState["ID"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["ID"] = value;
}
}
public string Reg
{
get
{
String s = (String)ViewState["Reg"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Reg"] = value;
}
}

protected override void RenderContents(HtmlTextWriter output)
{
// output.RenderBeginTag(output);
output.Write(string.Format("<input type=\"text\" Id=\"{0}\" onkeyup=\"this.value=this.value.replace(/{1}/,'')\" value=\"{2}\"></input>", ID,Reg,Text));
// output.RenderEndTag(output);
//output.Write(Text);
}
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics