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
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