'Last Update : 2008-07-13
'Tel :
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
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
End Enum
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Display Decimal for Number")>
Property _Key() As String
Get
If ViewState("myKey") Is Nothing Then
Return String.Empty
Else
Return CType(ViewState("myKey"), String)
End If
End Get
Set(ByVal Value As String)
ViewState("myKey") = Value
End Set
End Property
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Display Decimal for Number")>
Property _AllowInputType() As InputType
Get
If ViewState("AllowInputType") Is Nothing Then
Return InputType.Text
Else
Return CType(ViewState("AllowInputType"), InputType)
End If
End Get
Set(ByVal Value As InputType)
ViewState("AllowInputType") = Value
End Set
End Property
<Bindable(False), Category("Appearance"), DefaultValue("None"), Localizable(True), Description("Auto set format on blur")>
Property _AllowDisplayDecimal() As DisplayDecimal
Get
If ViewState("AllowDisplayDecimal") Is Nothing Then
Return DisplayDecimal.None
Else
Return CType(ViewState("AllowDisplayDecimal"), DisplayDecimal)
End If
End Get
Set(ByVal Value As DisplayDecimal)
ViewState("AllowDisplayDecimal") = Value
End Set
End Property
<Bindable(False), Category("Appearance"), DefaultValue(True), Localizable(True), Description("Auto set format on blur")>
Property _FormatOnblur() As Boolean
Get
If ViewState("FormatOnblur") Is Nothing Then
Return True
Else
Return CType(ViewState("FormatOnblur"), Boolean)
End If
End Get
Set(ByVal Value As Boolean)
ViewState("FormatOnblur") = Value
End Set
End Property
<Bindable(False), Category("Appearance"), DefaultValue(False), Localizable(True), Description("Render this to Literal")>
Property _DisplayAsLiteral() As Boolean
Get
If ViewState("DisplayAsLiteral") Is Nothing Then
Return False
Else
Return CType(ViewState("DisplayAsLiteral"), Boolean)
End If
'Return DirectCast(ViewState("DisplayAsLiteral"), Boolean)
End Get
Set(ByVal Value As Boolean)
ViewState("DisplayAsLiteral") = Value
End Set
End Property
<Bindable(False), Category("Appearance"), DefaultValue(False), Localizable(True), Description("Display Commma")>
Property _DisplayComma() As Boolean
Get
If ViewState("DisplayComma") Is Nothing Then
Return False
Else
Return CType(ViewState("DisplayComma"), Boolean)
End If
End Get
Set(ByVal Value As Boolean)
ViewState("DisplayComma") = 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
'+55555
Else
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") = "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 & ");"
End If
MyBase.Attributes("onblur") = "this.value = formatCurrency" & dec
End If
End If
MyBase.OnInit(e)
End Sub
End Class