I am having a problem with the WebMaskEdit control. I have this control within a Row Edit Template user control for the web grid. When I retrieve the value from the database, the value input into the WebMaskEdit control is askew.
I have a input mask of this: 999#.CCCCCCCCCCCCCCCCC
Basically the data looks like this:
1000.102SOMECHARACTERS1001.102SOMECHARACTERS123.001SOMECHARACTERS12.SOMECHARACTERSetc....Upon loading of the user control, the data (12.SOMECHARACTERS) is shown as:
12_S.MECHARACTERS
Am I missing something on this?
Hi Robert,
WebMaskEdit is designed to work with strings which have strict format. If mask-flags are optional, then it can skip those empty positions while "get" Value, but it cannot do that on "set" Value. The value for "set" should match with mask.
I suggest you to use WebTextEdit and filter its keyboard. I wrote for you a sample which will keep value in editor according to your mask. You may enhance its logic and add more validation cases. The keydown is used to disable backspace and delete key when user wants to erase "." character. The keypress is used to validate entries in front of "." character.
<script type="text/javascript">function WebTextEdit1_KeyPress(oEdit, keyCode, oEvent){ var caret = oEdit.getSelection(true); var txt = oEdit.getText(); var dot = txt.indexOf('.'); var digit = keyCode >= 48 && keyCode <= 57; var cancel = (txt.length < 2 || caret < 2) && !digit; if(dot < 0 && txt.length > 3 && keyCode != 46) cancel = true; if(dot > 0 && keyCode == 46) cancel = true; if(caret <= dot && !digit) cancel = true; if(dot > 3 && caret <= dot) cancel = true; if(cancel) oEvent.cancel = true;}function WebTextEdit1_KeyDown(oEdit, keyCode, oEvent){ if(keyCode != 8 && keyCode != 46) return; var caret = oEdit.getSelection(true); var txt = oEdit.getText(); var cancel = false; if(keyCode == 8 && caret > 1 && txt.charAt(caret - 1) == '.') cancel = true; if(keyCode == 46 && caret > 0 && txt.charAt(caret) == '.') cancel = true; if(cancel) oEvent.cancel = true;}</script>
<igtxt:WebTextEdit ID="WebTextEdit1" runat="server"> <ClientSideEvents KeyPress="WebTextEdit1_KeyPress" KeyDown="WebTextEdit1_KeyDown" /></igtxt:WebTextEdit>