.NET流水账

一个真正的开明进步的国家,不是一群奴才造成的,是要有独立个性,有自由思考的人造成的。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
Public Class NumericTextbox
   Inherits TextBox
   Private m_AllowDecimal As Boolean = False

   Public Property AllowDecimal() As Boolean
      Get
         Return m_AllowDecimal
      End Get 
      Set(ByVal Value As Boolean) 
         m_AllowDecimal = Value 
      End Set
   End Property

   Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs) 
      If Not Page.IsClientScriptBlockRegistered("ValidateNumeric") Then 
         Dim _script As New StringBuilder("")
         _script.Append("<SCRIPT language='javascript'>")
         _script.Append("function _NumericTextbox_ValidateNumeric(){" & NewLine)
         _script.Append("var keyCode = window.event.keyCode; " & NewLine) 
         If Not m_AllowDecimal Then 
            _script.Append("if (keyCode > 57 || keyCode < 48) " & NewLine) 
         Else 
            _script.Append("if ((keyCode > 57 ||keyCode < 48) && keyCode ! = 46) " & NewLine)
         End If 
         _script.Append(" window.event.returnValue = false;}</SCRIPT> ")
         Page.RegisterClientScriptBlock("___NumericTextboxValidateNumeric", _script.ToString())
      End If
      Attributes.Add("onKeyPress", "_NumericTextbox_ValidateNumeric()")
      MyBase.OnPreRender(e)
   End Sub
End Class
posted on 2005-09-30 09:53  DalianGary  阅读(840)  评论(0编辑  收藏  举报