Thursday, March 22, 2012

Mask Edit control

Hi,

Can anyone help me in creating a maskedit control in asp.net

Thanks in advance

Cheers
ChakriTo get the same behavior as a masked textbox in Windows is very difficult on web browsers. Internet Explorer (DHTML-based) and Mozilla (W3C DOM-based) have different ways to handle where the insertion point is. (In fact, I haven't found a good way in IE.)

As a result, I recommend using a much simpler model that works for most browsers and handles when the browser doesn't have javascript enabled:
1. Filter out unwanted keystrokes. You will have a character set of valid keystrokes across all positions. That means you can allow illegal patterns. For example, if you want to allow a decimal number, the character set is digits + decimal char. The filter will still allow something like this: "3.2.43.452". Attach the filter to the onkeypress event of the textbox. Use Microsoft's DHTML reference for info about onkeypress:DHTML Reference.

2. Use a validator to confirm that the text matches the pattern you want. This will also solve the problem where javascript is disabled.

FYI: I include a FilteredTextBox and several numeric textboxes along with validators in myProfessional Validation And More. I have already solved the cross browser issues and these controls are in the field at 100s of sites.

0 comments:

Post a Comment