ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control Continued - Cute Features of this control
(Page 4 of 5 )
Since we now understand some of the rendering methods of this control, let us go through some of the cute features of my textbox control. I wanted my textbox control to accept only digits, or only alphabets, or any character. For that purpose, I need to validate certain of the “KeyPress” events at client-side JavaScript. Of course, I should also expose a property to the type of input it could accept. Based on all of these considerations, I declared an enumerated data type as follows:
Public Enum tInputType
[Characters]
[Digits]
[Alphabets]
End Enum
The property has been implemented as follows:
Property InputType() As tInputType
Get
If viewstate("InputType") Is Nothing Then
viewstate("InputType") = tInputType.Characters
End If
Return viewstate("InputType")
End Get
Set(ByVal Value As tInputType)
viewstate("InputType") = Value
End Set
End Property
I hope you can understand the above (if you are new to view state, I suggest you go through my previous articles first). Next, I would also like my textbox to be highlighted with red background, when the user passes through the control without providing any data. That means empty value, acceptable or not. Even this should be working the JavaScript. And I designed the following property to deal with that issue:
Property IsCompulsory() As Boolean
Get
If viewstate("IsCompulsory") Is Nothing Then
viewstate("IsCompulsory") = False
End If
Return viewstate("IsCompulsory")
End Get
Set(ByVal Value As Boolean)
viewstate("IsCompulsory") = Value
End Set
End Property
Next: Briefly understanding the JavaScript implementation >>
More ASP.NET Articles
More By Jagadish Chaterjee