Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
'<DefaultProperty("Text"), ToolboxData("<{0}:WL_Controls.WL_TextBox1 runat=server></{0}:WL_Controls.WL_TextBox1>")>
<ControlBuilder(GetType(System.Web.UI.WebControls.TextBoxControlBuilder)), Designer("System.Web.UI.Design.ControlDesigner"), DefaultProperty("ID"), ToolboxData("<{0}:WL_TextBox runat=server></{0}:WL_TextBox>")> _
Public Class WL_TextBox
Inherits TextBox
Public Enum InputType
Text
[Integer]
Number
End Enum
Public Enum DisplayDecimal
None
One
Two
Tree
Four
Five
...
...
...
<Bindable(False), Category("Appearance"), DefaultValue(False), Localizable(True), Description("isUpperCase")>
Property _isUpperCase() As Boolean
Get
If ViewState("_isUpperCase") Is Nothing Then
Return False
Else
Return CType(ViewState("_isUpperCase"), Boolean)
End If
'Return DirectCast(ViewState("DisplayAsLiteral"), Boolean)
End Get
Set(ByVal Value As Boolean)
ViewState("_isUpperCase") = Value
End Set
End Property
Protected Overrides Sub RenderContents(writer As System.Web.UI.HtmlTextWriter)
If _DisplayAsLiteral = True Then 'Default Tag Span
Dim x As New Literal() With {.ID = Me.ID}
If _AllowInputType = InputType.Integer Then
If _DisplayComma Then
Me.Text = String.Format("{0:N0}", Val(Me.Text))
End If
ElseIf _AllowInputType = InputType.Number Then
x.Text = Me.Text
End If
x.RenderControl(writer)
Else
MyBase.RenderContents(writer)
End If
End Sub
Protected Overrides Sub OnInit(e As System.EventArgs)
If (_AllowInputType <> InputType.Text) AndAlso (_FormatOnblur = True) Then
If Not MyBase.Page.ClientScript.IsClientScriptIncludeRegistered("WL_Controls_JScript") Then
MyBase.Page.ClientScript.RegisterClientScriptInclude("WL_Controls_JScript", MyBase.Page.ClientScript.GetWebResourceUrl(MyBase.GetType(), "WL_Controls.WL_Controls.js"))
'HttpContext.Current.Response.Write("Not Register WL_Controls JScript ท่านจำเป็นต้องลงทะเบียนเพื่อเสียเงิน" & "<br/>")
End If
If _AllowInputType = InputType.Integer Then
MyBase.Attributes("onkeypress") = "var cv = (document.all) ? event.keyCode : event.which; return (cv >=48 && cv <=57);"
'MyBase.Attributes("onkeypress") = "return integerOnly();"
End If
If _AllowInputType = InputType.Number Then
MyBase.Attributes("onkeypress") = "return numberOnly(this);"
Dim dec As String = "(this.value);"
If _AllowDisplayDecimal <> DisplayDecimal.None Then
dec = "(this.value, " & _AllowDisplayDecimal & ");"
'dec = "(this.value, '.', " & _AllowDisplayDecimal & ");"
End If
'MyBase.Attributes("onblur") = "this.value = formatCurrency" & dec
'MyBase.Attributes("onblur") = "this.value = formatCurrency2015" & dec
MyBase.Attributes("onblur") = "this.value = formatCurrency2016" & dec
End If
ElseIf (_AllowInputType = InputType.Text AndAlso _isUpperCase = True) Then
MyBase.Attributes("onkeypress") = "var cv = (document.all) ? event.keyCode : event.which; if (cv!='8' && cv!='0' && cv!='27') {this.value+=String.fromCharCode(cv).toUpperCase(); return false;};"
End If
MyBase.OnInit(e)
End Sub
End Class