TextBox post-back on each character entry?

GornHorse

Well-known member
Joined
May 27, 2003
Messages
105
Location
Australia
Hi there,

Just wondering if its possible to get a textbox to post-back at each character being entered into the textbox, rather than having to wait until the user tabs out of the textbox to have the textchanged event occur.

The reason being, i have a credit card text field, with which i want to have a space placed after every 4-digits are entered into the textbox.
Ie, after a user types in "1234", the textbox text would change to "1234 " etc. Therefore, a full credit card string may be something like "1234 5678 1234 5678". The code that i have at the moment is as follows:


Private Sub tbCCNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbCCNumber.TextChanged
If Not me.IsInitializing then
cc_counter = cc_counter + 1
cc_stringtotal = cc_stringtotal + 1
Dim currccstring as string
if (cc_counter = 4) and (cc_stringtotal <> 19) then
currccstring = tbCCNumber.Text
tbCCNumber.Text = currccstring & " "
cc_counter = 0
end if
end if
end sub



Thanks for reading this, and i hope that you may be able to help me with this very soon.

Regards,
Michelle
 
Posting back on each character would get really slow, there is two other ways though that I can think of.

1. Write client-side javascript to format your text entry into the format you want.
2. Create a user control that accepts input in the desired format.

The javascript approach is probably the easiest maybe somebody could post some sample javascript because I am extremly bad at javascript and wouldnt want to embarass myself.
 
Back
Top